OpenProcess
The OpenProcess
function returns a handle of an existing process object.
HANDLE OpenProcess(
DWORD dwDesiredAccess, |
// access flag |
BOOL bInheritHandle, |
// handle
inheritance flag |
DWORD dwProcessId |
// process
identifier |
); |
|
Parameters
dwDesiredAccess
Specifies the
access to the process object. For operating systems that support security
checking, this access is checked against any security descriptor for the target
process. Any combination of the following access flags can be specified in
addition to the STANDARD_RIGHTS_REQUIRED access flags:
Access |
Description |
PROCESS_ALL_ACCESS |
Specifies
all possible access flags for the process object. |
PROCESS_CREATE_PROCESS |
Used
internally. |
PROCESS_CREATE_THREAD |
Enables
using the process handle in the CreateRemoteThread |
PROCESS_DUP_HANDLE |
Enables
using the process handle as either the source or target process in the DuplicateHandle |
PROCESS_QUERY_INFORMATION |
Enables
using the process handle in the GetExitCodeProcess |
PROCESS_SET_INFORMATION |
Enables
using the process handle in the SetPriorityClass |
PROCESS_TERMINATE |
Enables
using the process handle in the TerminateProcess |
PROCESS_VM_OPERATION |
Enables
using the process handle in the VirtualProtectEx |
PROCESS_VM_READ |
Enables
using the process handle in the ReadProcessMemory |
PROCESS_VM_WRITE |
Enables
using the process handle in the WriteProcessMemory |
SYNCHRONIZE |
Windows
NT only: Enables using the process
handle in any of the wait functions |
bInheritHandle
Specifies
whether the returned handle can be inherited by a new process created by the
current process. If TRUE, the handle is inheritable.
dwProcessId
Specifies the
process identifier of the process to open.
Return Values
If the
function succeeds, the return value is an open handle of the specified process.
If the
function fails, the return value is NULL. To get extended error information,
call GetLastError
Remarks
The handle
returned by the OpenProcess function can be used in any function that
requires a handle to a process, such as the wait functions
When you are
finished with the handle, be sure to close it using the CloseHandle
function.
See Also