函数参考


_Security__DuplicateTokenEx

Creates a new access token that duplicates an existing token

#include <Security.au3>
_Security__DuplicateTokenEx($hExistingToken, $iDesiredAccess, $iImpersonationLevel, $iTokenType)

参数

$hExistingToken A handle to an access token opened with TOKEN_DUPLICATE access
$iDesiredAccess The requested access rights for the new token
$iImpersonationLevel The impersonation level of the new token
$iTokenType The type of new token

返回值

Success: A handle that receives the new token
Failure: 0

注意/说明

None.

相关

_Security__OpenProcessToken, _Security__OpenThreadToken, _Security__OpenThreadTokenEx

详情参考

在MSDN中搜索


示例/演示


#include <ProcessConstants.au3>
#include <SecurityConstants.au3>
#include <Security.au3>
#include <WinAPI.au3>

Local $hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, 0, ProcessExists("explorer.exe"))
; If successful
If $hProcess Then
    ; Token...
    Local $hTokOriginal = _Security__OpenProcessToken($hProcess, $TOKEN_ALL_ACCESS)
    ; Process handle is no longer needed. Close it
    _WinAPI_CloseHandle($hProcess)
    ; If successful
    If $hTokOriginal Then
        ; Duplicate the original token
        Local $hTokDuplicate = _Security__DuplicateTokenEx($hTokOriginal, $TOKEN_ALL_ACCESS, $SECURITYIMPERSONATION, $TOKENPRIMARY)
        ; Close the original token
        _WinAPI_CloseHandle($hTokOriginal)
        ; What's created is a primary token (!)
        ; ... Do whatever with that token here ...

        MsgBox(262144, "DuplicateTokenEx", "$hTokDuplicate = " & $hTokDuplicate)

        ; Close that token when done
        _WinAPI_CloseHandle($hTokDuplicate)
    EndIf
EndIf