WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Network Related

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get User SID

 Keywords: Get User UserID Username ID SID 

#DefineFunction GetSIDFromUser(UserName)
  If StrIndex(UserName, "\", 0, @FWDSCAN) > 0 Then
    DomainName = ItemExtract(1, UserName, "\")
    UserName = ItemExtract(2, UserName, "\")
  Else
    DomainName = Environment("UserDomain")
  EndIf
  WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!/root/cimv2:Win32_UserAccount.Domain='" : DomainName : "',Name='" : UserName : "'")
  Result = WMIUser.SID
  Return Result
#EndFunction

username = Environment('Username')
sid = GetSIDFromUser(username)
Pause(username, sid)
Exit

Article ID:   W18376
Filename:   Get User SID.txt
File Created: 2010:12:21:14:13:16
Last Updated: 2010:12:21:14:13:16