Function Reference


_Security__OpenThreadToken

Opens the access token associated with a thread

#include <Security.au3>
_Security__OpenThreadToken ( $iAccess [, $hThread = 0 [, $bOpenAsSelf = False]] )

Parameters

$iAccess Access mask that specifies the requested types of access to the access token.
These requested access types are reconciled against the token's discretionary access control list (DACL) to determine which accesses are granted or denied.
$hThread [optional] Handle to the thread whose access token is opened
$bOpenAsSelf [optional] Indicates whether the access check is to be made against the security context of the thread calling the OpenThreadToken function or against the security context of the process for the calling thread.
If this parameter is False, the access check is performed using the security context for the calling thread.
If the thread is impersonating a client, this security context can be that of a client process.
If this parameter is True, the access check is made using the security context of the process for the calling thread.

Return Value

Success: a handle to the newly opened access token.
Failure: 0.

Remarks

OpenThreadToken will fail if not impersonating.

Related

_Security__OpenProcessToken, _Security__OpenThreadTokenEx

See Also

Search OpenThreadToken in MSDN Library.

Example

#include <Security.au3>
#include <SecurityConstants.au3>
#include <WinAPIError.au3>
#include <WinAPIHObj.au3>

Local $hToken = _Security__OpenThreadToken($TOKEN_ADJUST_PRIVILEGES)
If $hToken Then
        ConsoleWrite("$hToken is " & $hToken & @CRLF)
        ; $hToken it this thread's token with $TOKEN_ADJUST_PRIVILEGES access

        ; ... The rest of the token work here...

        _WinAPI_CloseHandle($hToken)
Else
        ConsoleWrite(_WinAPI_GetLastErrorMessage())
        ; Read remarks for _Security__OpenThreadToken
EndIf