Good day.

I develop asp.net site for local network. I take data from AD (using DirectoryServices ), and the question arose how to get the SID of the user specified by the user.

I would also be grateful if someone else tells you whether you can exclude a specific folder from the search in DirectoryServices .

  • See SID in Win32_UserAccount via WMIService - Konst

1 answer 1

Thanks to hints Konst sketched the solution. the function gets the SID based on the user login.

Function win32_SID(userlogin As String) As String Dim SID As String = "" Dim objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") If objWMIService IsNot Nothing Then Dim colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount Where Domain='DomainName' AND Status='OK' AND Name='" & userlogin & "'") For Each objItem In colItems SID = "SID - " & objItem.SID Next End If Return SID End Function