Jump to content

Help Me with GetSid!


Recommended Posts

I need a function that returns SID of a user. I wrote this:

Func GetSid($_Username)
@ComputerName & '\' & $_Username & '> ' & @TempDir & '\getsid.tmp' )
    FileDelete(@TempDir & '\getsid.tmp')
    Run(@ComSpec & ' /c "' & @ScriptDir & '\psgetsid.exe" ' & $_Username & '> ' & @TempDir & '\getsid.tmp', '', @SW_HIDE)
;MsgBox(0,'','1')
    [b]Sleep(50)[/b]
    Local $f= FileOpen(@TempDir & '\getsid.tmp',0)
    Local $a= FileReadLine($f,2)
    FileClose($f)
    If StringStripWS ( $a, 8) <> "" Then Return $a 
    Return $_Username
EndFunc

but it works too slow because it needs a pause

Link to comment
Share on other sites

Try this:

$user=envget("username")

$i=1

while 1

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList",$i)

$i=$i+1

if @error <> 0 Then ExitLoop

$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $var,"ProfileImagePath")

If StringInStr($var2, $user) Then

MsgBox(4096, "SID " ,"Value of Logon User " & @CRLF & $var)

Else

EndIf

wend

Link to comment
Share on other sites

I need a function that returns SID of a user. I wrote this:

but it works too slow because it needs a pause

1.) You can improve the speed if you use RunWait() instead of Run(). This will eliminate the sleep, however it's unclear to me how a 50 millisecond will slow down the whole script anyway....

2.) You can use WMI and with this classes: Win32_Account, Win32_UserAccount (search the forum for WMI and Scriptomatic).

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Try this:

$Domain = EnvGet("USERDOMAIN")
MsgBox(0, "SID", $Domain & "\" & @UserName & ":  " & _GetSID(@UserName, $Domain))

Func _GetSID($Username, $UserDomain = '')
    Local $objWMIService, $objAccount
    If $UserDomain = '' Then $UserDomain = EnvGet("USERDOMAIN")
    $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
    $objAccount = $objWMIService.Get _
            ("Win32_UserAccount.Name='" & @Username & "',Domain='" & $UserDomain & "'")
    Return $objAccount.SID
EndFunc
BlueBearrOddly enough, this is what I do for fun.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...