(view source code of user2sid.vbs as plain text)
Option Explicit
Dim objAccount, objWMIService, wshNetwork
Dim strComputer, strDomain, strSID, strUser
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strComputer = wshNetwork.ComputerName
Set wshNetwork = Nothing
With WScript.Arguments
If .Named.Count > 0 Then Syntax
Select Case .Unnamed.Count
Case 1
strUser = .Unnamed(0)
If InStr( strUser, "\" ) Then
strDomain = Left( strUser, InStr( strUser, "\" ) - 1 )
strUser = Mid( strUser, InStr( strUser, "\" ) + 1 )
Else
strDomain = strComputer
strUser = .Unnamed(0)
End If
Case 2
strDomain = .Unnamed(1)
strUser = .Unnamed(0)
Case Else
Syntax
End Select
End With
If InStr( strComputer, " " ) Then Syntax
If InStr( strDomain, " " ) Then Syntax
If InStr( strUser, " " ) Then Syntax
If InStr( strUser, "\" ) Then Syntax
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
On Error Resume Next
Set objAccount = objWMIService.Get( "Win32_UserAccount.Name='" & strUser & "',Domain='" & strDomain & "'" )
If Err Then Syntax
On Error Goto 0
Wscript.Echo objAccount.SID
Set objAccount = Nothing
Set objWMIService = Nothing
Sub Syntax
Dim strMsg
strMsg = vbCrLf _
& "User2SID.vbs, Version 1.00" _
& vbCrLf _
& "Display the Security ID (SID) for the specified user" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT.EXE //NoLogo USER2SID.VBS user_id [ domain ]" _
& vbCrLf _
& " or: CSCRIPT.EXE //NoLogo USER2SID.VBS user_id [ computer ]" _
& vbCrLf _
& " or: CSCRIPT.EXE //NoLogo USER2SID.VBS domain\user_id" _
& vbCrLf _
& " or: CSCRIPT.EXE //NoLogo USER2SID.VBS computer\user_id" _
& vbCrLf & vbCrLf _
& "Notes: If no domain or computer is specified, the local computer is assumed." _
& vbCrLf _
& " Do not use double backslashes to prefix computer names." _
& vbCrLf _
& " No spaces are allowed in user, computer or domain names." _
& vbCrLf & vbCrLf _
& "Core functionality borrowed from the Microsoft Scripting Guys" _
& vbCrLf _
& "www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1203.mspx" _
& vbCrLf _
& "Command line parsing by Rob van der Woude" _
& vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2024-04-16; loaded in 0.0086 seconds