OpenProcess

Syntax

HANDLE OpenProcess(
  DWORD dwDesiredAccess,
  BOOL  bInheritHandle,
  DWORD dwProcessId
);

Parameters

  • dwDesiredAccess [in]
    The access to the process object. This is a bitmask that specifies the type of access to the process for which the calling thread is to be opened. For a list of access rights, see Process Security and Access Rights.
    PROCESS_ALL_ACCESS
    PROCESS_CREATE_THREAD
    PROCESS_QUERY_INFORMATION
  • bInheritHandle [in]
    If this parameter is TRUE, each handle in the process is inherited by the new process. Otherwise, the handles are not inherited.
  • dwProcessId [in]
    The identifier of the process to be opened.

Return Value

  • If the function succeeds, the return value is an open handle to the specified process.
  • If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

To compile an application that uses this function, the _WIN32_WINNT macro must be set to 0x0400 or later. For more information, see Using the Windows Headers.

The calling process must have the appropriate privileges for the target process. For example, to open a process with PROCESS_VM_READ access, the calling process must have SeDebugPrivilege enabled.

You can obtain the process identifier of the current process by calling the GetCurrentProcessId function.

To obtain a handle to the current process, you can use the special value (HANDLE)-1 or GetCurrentProcess().

Requirements

Minimum supported client

Windows 2000 Professional.

Minimum supported server

Windows 2000 Server.

Header

Declared in processthreadsapi.h, include windows.h.

Library

Use Kernel32.lib.

DLL

Kernel32.dll.

See Also