给你写一个,在本机上测试成功。以下是AutoIt的代码,具体程序在我的网盘里:http://pusofalse.ys168.com/, 目录AutoIt,AddAccountRights.rar- ; ==================== PRIVILEGE =====================
- ; SeCreateTokenPrivilege
- ; SeAssignPrimaryTokenPrivilege
- ; SeLockMemoryPrivilege
- ; SeIncreaseQuotaPrivilege
- ; SeUnsolicitedInputPrivilege
- ; SeMachineAccountPrivilege
- ; SeTcbPrivilege
- ; SeSecurityPrivilege
- ; SeTakeOwnershipPrivilege
- ; SeLoadDriverPrivilege
- ; SeSystemProfilePrivilege
- ; SeSystemtimePrivilege
- ; SeProfileSingleProcessPrivilege
- ; SeIncreaseBasePriorityPrivilege
- ; SeCreatePagefilePrivilege
- ; SeCreatePermanentPrivilege
- ; SeBackupPrivilege
- ; SeRestorePrivilege
- ; SeShutdownPrivilege
- ; SeDebugPrivilege
- ; SeAuditPrivilege
- ; SeSystemEnvironmentPrivilege
- ; SeChangeNotifyPrivilege
- ; SeRemoteShutdownPrivilege
- ; ============================================================
-
-
- ; ================ ACCOUNT RIGHT =================
- ; SeBatchLogonRight
- ; SeDenyBatchLogonRight
- ; SeDenyInteractiveLogonRight
- ; SeDenyNetworkLogonRight
- ; SeDenyRemoteInteractiveLogonRight
- ; SeDenyServiceLogonRight
- ; SeInteractiveLogonRight
- ; SeNetworkLogonRight
- ; SeRemoteInteractiveLogonRight
- ; SeServiceLogonRight
- ; ============================================================
-
- CONST $ERROR_INVALID_SID = 1337
-
- $iResult = _LsaAddAccountRights("guest", "SeRemoteShutdownPrivilege")
- If $iResult = False Then
- Msgbox(48, "", "Failed, ErrorCode: " & @error)
- Else
- Msgbox(64, "", "Succeed, ErrorCode: " & @error)
- EndIf
-
- Func _LsaAddAccountRights($sName, $sRight)
- Local $hPolicy, $tSid, $pSid, $iLength, $iSysError
- Local $tUnicode, $pUnicode, $iResult, $tRight, $pRight
-
- $tSid = _LookupAccountName($sName)
- $pSid = DllStructGetPtr($tSid)
- If Not _IsValidSid($pSid) Then Return SetError(@error, 0, 0)
- $hPolicy = _LsaOpenPolicy(0x811)
-
- $iLength = StringLen($sRight) * 2
- $tRight = DllStructCreate("wchar[" & $iLength & "]")
- $pRight = DllStructGetPtr($tRight)
- DllStructSetData($tRight, 1, $sRight)
-
- $tUnicode = DllStructCreate("ushort Length;ushort MemSize;ptr wBuffer")
- $pUnicode = DllStructGetPtr($tUnicode)
- DllStructSetData($tUnicode, "Length", $iLength)
- DllStructSetData($tUnicode, "MemSize", $iLength + 2)
- DllStructSetData($tUnicode, "wBuffer", $pRight)
-
- $iResult = DllCall("advapi32.dll", "dword", "LsaAddAccountRights", _
- "hWnd", $hPolicy, "ptr", $pSid, _
- "ptr", $pUnicode, "ulong", 1)
- $tSid = 0
- _LsaClose($hPolicy)
- $iSysError = _LsaNtStatusToWinError($iResult[0])
- Return SetError($iSysError, 0, $iSysError = 0)
- EndFunc ;==>_LsaAddAccountRights()
-
- Func _LsaOpenPolicy($iAccess)
- Local $hPolicy, $tLsaAttr, $pLsaAttr
-
- $tLsaAttr = DllStructCreate("ulong;hWnd;ptr;ulong;ptr[2]")
- $pLsaAttr = DllStructGetPtr($tLsaAttr)
-
- $hPolicy = DllCall("advapi32.dll", "ulong", "LsaOpenPolicy", _
- "ptr", 0, "ptr", $pLsaAttr, "int", $iAccess, "hWnd*", 0)
- Return SetError(_LsaNtStatusToWinError($hPolicy[0]), 0, $hPolicy[4])
- EndFunc ;==>_LsaOpenPolicy()
-
- Func _LsaClose($hPolicy)
- Local $iResult
- $iResult = DllCall("advapi32.dll", "ulong", "LsaClose", "hWnd", $hPolicy)
- Return SetError(_LsaNtStatusToWinError($iResult[0]), 0, $iResult[0] = 0)
- EndFunc ;==>_LsaClose()
-
-
- Func _LsaNtStatusToWinError($iStatusCode)
- Local $iResult
- $iResult = DllCall("advapi32.dll", "ulong", "LsaNtStatusToWinError", "dword", $iStatusCode)
- Return $iResult[0]
- EndFunc ;==>_LsaNtStatusToWinError()
-
-
- Func _LookupAccountName($sName, $sSystem = "")
- Local $iResult, $tSid, $pSid, $tDomain, $pDomain
-
- $iResult = DllCall("advapi32.dll", "int", "LookupAccountName", _
- "str", $sSystem, "str", $sName, _
- "ptr", 0, "int*", 0, "ptr", 0, "int*", 0, "int*", 0)
- If $iResult[4] = 0 Then Return SetError($ERROR_INVALID_SID, 0, 0)
-
- $tSid = DllStructCreate("ubyte[" & $iResult[4] & "]")
- $tDomain = DllStructCreate("ubyte[" & $iResult[6] & "]")
- $pSid = DllStructGetPtr($tSid)
- $pDomain = DllStructGetPtr($tDomain)
-
- $iResult = DllCall("advapi32.dll", "int", "LookupAccountName", _
- "str", $sSystem ,"str", $sName, _
- "ptr", $pSid, "int*", $iResult[4], _
- "ptr", $pDomain, "int*", $iResult[6], "int*", 0)
- Return SetError(Not $iResult[0], $iResult[7], $tSid)
- EndFunc ;==>_LookupAccountName()
-
- Func _IsValidSid($pSid)
- Local $iResult
- $iResult = DllCall("advapi32.dll", "int", "IsValidSid", "ptr", $pSid)
- If $iResult[0] Then Return SetError(0, 0, True)
- Return SetError($ERROR_INVALID_SID, 0, 0)
- EndFunc ;==>_IsValidSid()
复制代码
[ 本帖最后由 pusofalse 于 2009-5-13 00:54 编辑 ] |