Dirk Diggler Posted August 7, 2006 Posted August 7, 2006 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
Dirk Diggler Posted August 7, 2006 Author Posted August 7, 2006 Is it possible something like WinAPI? i'm not good in it....
b015979 Posted August 8, 2006 Posted August 8, 2006 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
Dirk Diggler Posted August 8, 2006 Author Posted August 8, 2006 it will work if profile exist. but if i want retrieve sid of a new domain user?
b015979 Posted August 8, 2006 Posted August 8, 2006 User SID's are generated by winlogon process and are unique on each machine ! So if no profile exist the user has not logon on a machine yet and there is NO User SID (as far as i know).
/dev/null Posted August 8, 2006 Posted August 8, 2006 I need a function that returns SID of a user. I wrote this:but it works too slow because it needs a pause1.) 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).CheersKurt __________________________________________________________(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 *
bluebearr Posted August 8, 2006 Posted August 8, 2006 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now