Sign in to follow this  
Followers 0
VIP

_GetSidAccount()

2 posts in this topic

#1 ·  Posted (edited)

;Not Work on XP
Func _GetSID($sComputerName = @ComputerName, $sUsername = @UserName)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!//" & $sComputerName & "/root/cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_UserAccount")
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If $sUsername = $oObjectItem.Name Then
                Return $oObjectItem.SID
            EndIf
        Next
    EndIf
    Return SetError(1, 0, 0)
EndFunc   ;==>_GetSID
;Not Work
_Security__GetAccountSid()

New Function:

;~ MsgBox(4096,  "",_GetSidAccount())

Func _GetSidAccount($sAccount=@UserName, $sSystem = "")
    Local $tData = DllStructCreate("byte SID[256]")
    Local $sCall = DllCall("advapi32.dll", "bool", "LookupAccountNameW", "wstr", $sSystem, "wstr", $sAccount, "struct*", $tData, "dword*", DllStructGetSize($tData), "wstr", "", "dword*", DllStructGetSize($tData), "int*", 0)
    If @error Or Not $sCall[0] Then Return SetError(@error, @extended, "")
    Local $pSID = DllStructGetPtr($tData, "SID")
    Local $iCall = DllCall("advapi32.dll", "bool", "IsValidSid", "struct*", $pSID)
    If @error Or Not $iCall[0] Then Return SetError(@error, @extended, "")
    Local $dCall = DllCall("advapi32.dll", "bool", "ConvertSidToStringSidW", "struct*", $pSID, "ptr*", 0)
    If @error Or Not $dCall[0] Then Return SetError(@error, @extended, "")
    Local $pStringSid = $dCall[2]
    Local $aLen = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $pStringSid)
    Local $sSID = DllStructGetData(DllStructCreate("wchar Text[" & $aLen[0] + 1 & "]", $pStringSid), "Text")
    DllCall("kernel32.dll", "handle", "LocalFree", "handle", $pStringSid)
    Return SetError(0, 0, $sSID)
EndFunc   ;==>_Security__LookupAccountName

Out: S-1-5-21-1708537768-1343024091-1957994488-500

SID_Trong_TK.png

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites



#include <Security.au3>

msgbox(0, '' , _GetSID(@UserName , "localhost"))

Func _GetSID($user , $comp)

$aSID = _Security__LookupAccountName($user , $comp)
$sOut = IsArray($aSID) ? $aSID[0] : "no match for " & $user

    return $sOut

EndFunc


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0