Tuesday, February 23, 2010

how to determine sid of a user

Nice VB script here from Daniel Petri:
http://www.petri.co.il/forums/showthread.php?t=21332

reprinted here for convenience
' www.petri.co.il/forums/showthread.php?p=61469#post61469

Const HKEY_USERS = &H80000003


strComputer = "." '<-- name of remote computer

Set objWMIService = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set Users = objWMIService.InstancesOf ("Win32_ComputerSystem")

for each User in Users
logonname = User.UserName
strUsr = Split(logonname,"\")(1)
strDomain = Split(logonname,"\")(0)
exit For
next

set colAccounts = objWMIService.ExecQuery _
("select * From Win32_UserAccount where " _
& "name = '" & strUsr & "' AND domain = '" & strDomain & "'")

For each objAccount in colAccounts
strSID = objAccount.SID
exit For
Next


wsh.echo "HKU-path for", logonname, vbNewLine & "HKEY_USERS\" & strSID & "\..."


OUTPUT
C:\WINDOWS>user.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

HKU-path for DOMAIN\sodo
HKEY_USERS\S-1-5-11-7177352686-8047241297-547765659-67771

5 comments:

Seech said...

Cool. Alternatively, in PowerShell:

PS> $user = New-Object System.Security.Principal.NTAccount("guest")
PS> $user.Translate([System.Security.Principal.SecurityIdentifier]).Value
S-1-5-21-4136385708-3597605771-3440172066-501

Cacasodo said...

Thanks dude!

Cacasodo said...

Had to use this again..nice, simple method!

rigmik said...

How about in windows 7? This works fine for XP but not for 7.

Cacasodo said...

Not sure. Sadly, my company is still on XP!

Feel free to drop me a line or ask me a question.