GetCurrentProcess
Retrieves a pseudo handle for the current process. A pseudo handle is a special constant that is valid within the context of the calling process or thread.
To use a pseudo handle to a process in another process, you must open the target process by calling the OpenProcess function.
HANDLE GetCurrentProcess(void);
C++
This function does not take any parameters.
The return value is a pseudo handle to the current process. This handle is created and used internally by the system and does not require closing.
A pseudo handle is a unique identifier of a specific instance of a process or thread. While a pseudo handle is valid within the context of the calling process or thread, it is not a process or thread handle that can be shared across processes. To open a handle to the current process that can be inherited by child processes, use the GetCurrentProcess macro.
The pseudo handle returned by GetCurrentProcess is equivalent to the handle that the system would create for the process. This pseudo handle is marked with the PROCESS_ALL_ACCESS access rights.
The pseudo handle is valid until the process is terminated. You do not need to close this handle; it is implicitly closed when the process terminates.
GetCurrentProcess(). For most operations within the current process, the pseudo handle is sufficient.
#include <windows.h>
#include <iostream>
int main() {
HANDLE hProcess = GetCurrentProcess();
DWORD processId = GetCurrentProcessId();
std::cout << "Current Process Handle: " << hProcess << std::endl;
std::cout << "Current Process ID: " << processId << std::endl;
// You can use hProcess with other API functions that require a process handle,
// for example, to set process information or to duplicate the handle.
// Note: You do not call CloseHandle for the handle returned by GetCurrentProcess.
return 0;
}
C++
| Platform | Minimum supported client | Minimum supported server |
|---|---|---|
| Windows 2000 Professional (Desktop) | Windows 2000 | Windows 2000 |
| Windows Server 2003 (Server) | Windows XP | Windows Server 2003 |
| Windows Vista | Windows Vista | Windows Server 2008 |
| Windows 7 | Windows 7 | Windows Server 2008 R2 |
| Windows 8 | Windows 8 | Windows Server 2012 |
| Windows 8.1 | Windows 8.1 | Windows Server 2012 R2 |
| Windows 10 | Windows 10 | Windows Server 2016 |
| Windows 11 | Windows 11 | Windows Server 2022 |