(view source code of sid2user.vbs as plain text)
Option Explicit
Dim arrTest, blnValidSID, i, objAccount, objWMIService, strMsg, strSID
blnValidSID = True
With WScript.Arguments
If .Named.Count > 0 Then Syntax
If .Unnamed.Count <> 1 Then Syntax
strSID = .Unnamed(0)
arrTest = Split( strSID, "-" )
If UBound( arrTest ) <> 3 And UBound( arrTest ) <> 7 Then blnValidSID = False
If UCase( arrTest(0) ) <> "S" Then blnValidSID = False
For i = 1 To UBound( arrTest )
If Not IsNumeric( arrTest(i) ) Then blnValidSID = False
If Not CStr( CLng( arrTest(i) ) ) = arrTest(i) Then blnValidSID = False
Next
End With
If blnValidSID = False Then
strMsg = "Error: invalid SID" & vbCrLf
Syntax
End If
Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
On Error Resume Next
Set objAccount = objWMIService.Get( "Win32_SID.SID='" & strSID & "'" )
If Err Then Syntax
If objAccount.AccountName = "" Then
WScript.Echo "-unknown-"
WScript.Quit 1
End If
On Error Goto 0
WScript.Echo objAccount.ReferencedDomainName & "\" & objAccount.AccountName
Set objAccount = Nothing
Set objWMIService = Nothing
Sub Syntax
strMsg = strMsg & vbCrLf _
& "SID2User.vbs, Version 1.00" _
& vbCrLf _
& "Display the user ID for the specified SID" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT.EXE //NoLogo SID2USER.VBS sid" _
& vbCrLf & vbCrLf _
& "Notes: The user ID is returned in DOMAIN\UserID format." _
& vbCrLf _
& " If the SID is not found, the script returns ""-unknown-""." _
& vbCrLf _
& " If the SID is invalid, an error message and this screen are displayed." _
& 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/error handling 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.0082 seconds