函数参考


_Security__SetPrivilege

启用或禁用本地令牌特权

#include <Security.au3>
_Security__SetPrivilege($hToken, $sPrivilege, $fEnable)

参数

$hToken 令牌句柄
$sPrivilege 特权名称
$fEnable 特权设置:
True - 启用特权
False - 禁用特权

返回值

成功: 返回 True
失败: 返回 False

注意/说明

None.

相关

_Security__AdjustTokenPrivileges

示例/演示


#RequireAdmin ; for this example to have sense

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

Local $hToken = _Security__OpenProcessToken(_WinAPI_GetCurrentProcess(), $TOKEN_ALL_ACCESS)
If $hToken Then
    ; $hToken it this process' token with $TOKEN_ALL_ACCESS access

    ; Enable SeDebugPrivilege for this token
    If _Security__SetPrivilege($hToken, $SE_DEBUG_NAME, True) Then
        ;... Do whatever with this token now and here...
        MsgBox(262144, "TokenPrivileges", $SE_DEBUG_NAME & " enabled!")
        ; Disable
        _Security__SetPrivilege($hToken, $SE_DEBUG_NAME, False)
        MsgBox(262144, "TokenPrivileges", $SE_DEBUG_NAME & " disabled!")
    EndIf

    ; Close handle when done
    _WinAPI_CloseHandle($hToken)
EndIf