Opens a handle to another process running on the system. This handle can be used to read and write to the other process memory or to inject code into the other process.
HANDLE WINAPI OpenProcess( _In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_ DWORD dwProcessId );
- dwDesiredAccess [in]
- The access to the process object. This access right is checked against the security descriptor for the process. This parameter can be one or more of the process access rights.
- If the caller has enabled the SeDebugPrivilege privilege, the requested access is granted regardless of the contents of the security descriptor.
- bInheritHandle [in]
- If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.
- dwProcessId [in]
- The identifier of the local process to be opened.
- If the specified process is the System Process (0x00000000), the function fails and the last error code is ERROR_INVALID_PARAMETER. If the specified process is the Idle process or one of the CSRSS processes, this function fails and the last error code is ERROR_ACCESS_DENIED because their access restrictions prevent user-level code from opening them.
- If you are using GetCurrentProcessId as an argument to this function, consider using GetCurrentProcess instead of OpenProcess, for improved performance.
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.