#include <lsasecur.au3>
; 域账户路径
Local $sObjectName = "DomainName\GroupName"
; 获取域账户SID
Local $pObjectSid = _SeLookupAccountName($sObjectName)
If $pObjectSid = 0 Then
MsgBox(48, "Error", _SeFormatMsg())
Exit
EndIf
; 获取本地策略句柄
Local $hPolicy = _SeOpenPolicy( BitOR($SE_POLICY_LOOKUP_NAMES, $SE_POLICY_CREATE_ACCOUNT))
If $hPolicy = 0 Then
MsgBox(48, "Error", _SeFormatMsg())
Exit
EndIf
; 在本地策略中为指定用户添加指定权限
If _SeAddAccountRight1($hPolicy, $pObjectSid, $SE_BATCH_LOGON_RIGHT) Then
MsgBox(48, "OK", "Done")
Else
MsgBox(48, "Error", _SeFormatMsg())
EndIf
_SeClosePolicy($hPolicy)
_SeHeapFree($pObjectSid)
Func _SeAddAccountRight1($hPolicy, $pAccountSid, $sUserRight)
Local $pUserRight = _SeInitBufferW($sUserRight)
Local $iResult
$iResult = DllCall("Advapi32.dll", "long", "LsaAddAccountRights", "ptr", $hPolicy, "ptr", $pAccountSid, "ptr", $pUserRight, "long", 1)
Return SetError($iResult[0], 0, $iResult[0] = 0)
EndFunc ;==>_SeAddAccountRight1
|