Function Reference


_Security__ImpersonateSelf

Obtains an access token that impersonates the calling process security context

#include <Security.au3>
_Security__ImpersonateSelf ( [$iLevel = $SECURITYIMPERSONATION] )

Parameters

$iLevel [optional] Impersonation level of the new token:
    $SECURITYANONYMOUS. The server process cannot obtain identification information about the client, and it cannot impersonate the client.
    $SECURITYIDENTIFICATION. The server process can obtain information about the client, such as security identifiers and privileges, but it cannot impersonate the client.
    $SECURITYIMPERSONATION. The server process can impersonate the clients security context on its local system. The server cannot impersonate the client on remote systems.
    $SECURITYDELEGATION. The server process can impersonate the client's security context on remote systems.

Return Value

Success: True.
Failure: False.

Related

_Security__OpenThreadTokenEx

See Also

Search ImpersonateSelf 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
    _WinAPI_CloseHandle($hToken)
Else
    ConsoleWrite("_Security__OpenThreadToken failed with error description: " & _WinAPI_GetLastErrorMessage() & @CRLF)
    ConsoleWrite("New attempt..." & @CRLF)

    ; Read remarks for  _Security__OpenThreadToken function
    _Security__ImpersonateSelf()
    $hToken = _Security__OpenThreadToken($TOKEN_ADJUST_PRIVILEGES)
    If $hToken Then
        ConsoleWrite(">>> SUCCESS, $hToken = " & $hToken & @CRLF)
        _WinAPI_CloseHandle($hToken)
    Else
        ConsoleWrite("!FAILED" & @CRLF)
    EndIf
EndIf