Under some circumstances, you may have the Security ID (SID) of a user but not know what that user’s login name is. This code, when supplied a valid SID, will return the login name of the user associated with that SID if it can be determined by Windows. If the user name cannot be determined, it returns “UNKNOWN”.
'
' Given a SID, this function will return the User Name
' or "UNKNOWN" if it couldn't find one.
'
function getUserFromSid(theSid)
on error resume next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount = objWMIService.Get _
("Win32_SID.SID='" & theSid & "'")
userName = objAccount.AccountName
if userName = "" then userName = "UNKNOWN"
getUserfromSid = userName
end Function
