> For the complete documentation index, see [llms.txt](https://rfc1918.gitbook.io/offsec/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rfc1918.gitbook.io/offsec/exploitation/win32-apis/openprocess.md).

# OpenProcess

## Syntax

```cpp
HANDLE OpenProcess(
  [in] DWORD dwDesiredAccess,
  [in] BOOL  bInheritHandle,
  [in] DWORD dwProcessId
);
```

{% embed url="<https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess>" %}

## Parameters <a href="#parameters" id="parameters"></a>

`[in] dwDesiredAccess`

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](https://learn.microsoft.com/en-us/windows/desktop/ProcThread/process-security-and-access-rights).

If the caller has enabled the [SeDebugPrivilege privilege](https://learn.microsoft.com/en-us/windows/win32/secauthz/privilege-constants#SE_DEBUG_NAME), the requested access is granted regardless of the contents of the security descriptor.

`[in] bInheritHandle`

If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.

`[in] dwProcessId`

The identifier of the local process to be opened.

If the specified process is the System Idle Process (0x00000000), the function fails and the last error code is `ERROR_INVALID_PARAMETER`. If the specified process is the System process or one of the Client Server Run-Time Subsystem (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](https://learn.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessid) as an argument to this function, consider using [GetCurrentProcess](https://learn.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess) instead of OpenProcess, for improved performance.
