OpenProcessToken Function Home
OpenProcessToken Function

The OpenProcessToken function opens the access token associated with a process.

Syntax

BOOL WINAPI OpenProcessToken(
  __in   HANDLE ProcessHandle,
  __in   DWORD DesiredAccess,
  __out  PHANDLE TokenHandle
);


Parameters

ProcessHandle [in]

A handle to the process whose access token is opened. The process must have the PROCESS_QUERY_INFORMATION access permission.

DesiredAccess [in]

Specifies an access mask that specifies the requested types of access to the access token. These requested access types are compared with the discretionary access control list (DACL) of the token to determine which accesses are granted or denied.

For a list of access rights for access tokens, see Access Rights for Access-Token Objects.

TokenHandle [out]

A pointer to a handle that identifies the newly opened access token when the function returns.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Close the access token handle returned through the TokenHandle parameter by calling CloseHandle.

Requirements

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

See Also

Access Control
Basic Access Control Functions
AccessCheck
AdjustTokenGroups
AdjustTokenPrivileges
CloseHandle
GetTokenInformation
OpenThreadToken
SetTokenInformation

Send comments about this topic to Microsoft

Build date: 9/11/2009

Community Content

vb.net syntax
Added by:dmex
<DllImport("advapi32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _
Public Shared Function OpenProcessToken(<[In]> ByVal ProcessToken As IntPtr, <[In]> ByVal DesiredAccess As TokenAccessLevels, <[In], Out> ByRef TokenHandle As IntPtr) As Boolean
End Function
C# syntax
Added by:dmex
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
internal static extern bool OpenProcessToken([In] IntPtr ProcessToken, [In] TokenAccessLevels DesiredAccess, [In, Out] ref IntPtr TokenHandle);
© 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