# 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pentestwiki.com/defense-evasion/windows-api/openprocess.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
