|
#include <LocalSecurityAuthority.au3>
$pSid = _LsaAddLocalUser("adminqt", "test",10, "")
If (@error = 2224) Then MsgBox(48, "", "test's user account already exists.")
If ($pSid) Then _HeapFree($pSid) ; 释放SID。
; 因为管理员组的SID已经确定,可直接获取其SID。
$pAdminsSid = _AllocateAndInitializeSid(5, 32, $DOMAIN_ALIAS_RID_ADMINS)
$sAdminsGroup = _LookupAccountSid($pAdminsSid, "") ; 根据SID获取管理员组的名称。
$sAdminsGroup = StringTrimLeft($sAdminsGroup, StringInStr($sAdminsGroup, "\"))
_FreeSid($pAdminsSid) ; 释放$pAdminsSid内存,已经不再需要。
$fResult = _LsaLocalGroupAddMembers($sAdminsGroup, "adminqt", "")
If ($fResult) Then
MsgBox(0, "", "Done")
Else
MsgBox(48, "", "Error code: " & @error)
EndIf |
|