GetCurrentProcess Function
GetCurrentProcess Function

Retrieves a pseudo handle for the current process.

Syntax

HANDLE WINAPI GetCurrentProcess(void);


Parameters

This function has no parameters.

Return Value

The return value is a pseudo handle to the current process.

Remarks

A pseudo handle is a special constant, currently (HANDLE)-1, that is interpreted as the current process handle. For compatibility with future operating systems, it is best to call GetCurrentProcess instead of hard-coding this constant value. The calling process can use a pseudo handle to specify its own process whenever a process handle is required. Pseudo handles are not inherited by child processes.

This handle has the PROCESS_ALL_ACCESS access right to the process object. For more information, see Process Security and Access Rights.

Windows Server 2003 and Windows XP/2000:  This handle has the maximum access allowed by the security descriptor of the process to the primary token of the process.

A process can create a "real" handle to itself that is valid in the context of other processes, or that can be inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function. A process can also use the OpenProcess function to open a real handle to itself.

The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with a pseudo handle has no effect. If the pseudo handle is duplicated by DuplicateHandle, the duplicate handle must be closed.

Examples

For an example, see Creating a Child Process with Redirected Input and Output.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See Also

CloseHandle
DuplicateHandle
GetCurrentProcessId
GetCurrentThread
OpenProcess
Process and Thread Functions
Processes

Send comments about this topic to Microsoft

Build date: 11/19/2009

Community Content

vb.net syntax
Added by:dmex
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetCurrentProcess() As IntPtr
End Function
C# syntax
Added by:dmex
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern IntPtr GetCurrentProcess();
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View