GetCurrentProcess

The GetCurrentProcess function retrieves a pseudo handle for the current process. A pseudo handle is a special constant that is equivalent to the real handle to the process.

Syntax

HANDLE GetCurrentProcess(
      void
    );
    

Parameters

This function does not take any parameters.

Return Value

Type Description
HANDLE

The return value is a pseudo handle for the current process. This pseudo handle cannot be used to identify the process in most functions; however, it is sufficient to specify the current process in those functions that require a process handle, such as the CloseHandle, DuplicateHandle, and WaitForSingleObject functions.

For a list of functions that accept pseudo handles, see Process Security and Access Rights.

Remarks

The pseudo handle returned by GetCurrentProcess is valid only within the calling process. It is not valid in another process. The handle is freed when the calling process terminates.

For functions that require a handle to the current process, use GetCurrentProcess to obtain a pseudo handle. This is more efficient than opening the process with OpenProcess using the PROCESS_ALL_ACCESS access mask.

Note

You should not close the pseudo handle returned by GetCurrentProcess. Closing a pseudo handle has no effect, but attempting to close it repeatedly can lead to unexpected behavior.

Important

While GetCurrentProcess returns a pseudo handle, it's important to understand its limitations. For operations requiring a truly unique and transferable handle, such as passing it to another process or performing more advanced security operations, use OpenProcess with the appropriate process identifier.

Requirements

   
Minimum supported client Windows 2000 Professional, Windows XP
Minimum supported server Windows 2000 Server
Header windows.h
Library Kernel32.lib
DLL Kernel32.dll

See Also