> For the complete documentation index, see [llms.txt](https://www.pentestwiki.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pentestwiki.com/defense-evasion/windows-api/openprocess.md).

# OpenProcess

OpenProcess는 실행 중인 프로세스의 핸들을 얻으며 다른 프로세스를 조작하는 모든 작업의 시작점으로 사용됩니다.

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

| 인자              | 설명         | 보편적인 값               |
| --------------- | ---------- | -------------------- |
| dwDesiredAccess | 접근 권한      | `PROCESS_ALL_ACCESS` |
| bInheritHandle  | 핸들 상속 여부   | FALSE                |
| dwProcessId     | 대상 프로세스 ID |                      |

## Example

```cpp
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
using namespace std;

HANDLE openProcessByPid(DWORD processId) {
    HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
    if (!hProc) {
        wcout << L"Failed to get Process handle" << endl;
    }
    return hProc;
}

int main() {
    int pid = 1234;
    HANDLE hProc = openProcessByPid(pid);
    CloseHandle(hProc);
    return 0;
}
```

## References

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