Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i find a users GUID? 2

Status
Not open for further replies.

hayabusaukuk

IS-IT--Management
Oct 2, 2007
50
GB
Straight-forward question, how can i find a users GUID? on a Win 2003 TS

Thanks
 
I use this script to get the SID from a username

Code:
GetSIDFromUser Inputbox("Username you want to find SID for","Get SID from user name")
 
Function GetSIDFromUser(UserName)

	If USerName = "" Then
		Exit Function
	End IF
	Dim DomainName, Result, WMIUser

	If InStr(UserName, "\") > 0 Then
		DomainName = Mid(UserName, 1, InStr(UserName, "\") - 1)
		UserName = Mid(UserName, InStr(UserName, "\") + 1)
	Else
		DomainName = CreateObject("WScript.Network").UserDomain
	End If

	On Error Resume Next
	Set WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!" & "/root/cimv2:Win32_UserAccount.Domain='" & DomainName & "'" & ",Name='" & trim(UserName) & "'")
	If Err = 0 Then 
		Result = WMIUser.SID 
	Else 
		Result = ""
	End If
	On Error GoTo 0
	If Result <> "" Then
		inputBox "SID for user: " & Username, "User SID", Result
	Else
		msgbox "Unable to find the requested users SID." & VbCrLF & "Most likely the user does not exist." , 16, "User SID"
	End If

	Set WMIUser = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top