Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WinNT:// provider searching for user by SID ?

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Is there way to search for a user account, given it's SID, using the WinNT:// provider? (I know it's possible with the LDAP provider, but need to do it with WinNT://)
 
Then with vbscript you must enumerate a group.members collection and get the SID to compare to the SID of the one your seraching for. Do you have the username ?
Or whats the format of the SID you're searching for ?


 
The SID is just a string (S-xxxx-xxxx...) and I'm trying to get the account name. I have no information on the object except the SID (no domain, no account name, etc).
 
i wouldnt have thought the SID string contains any direct reference to domain or account name, you will need to contact the domain and search for the account, then contact other domains if you dont find the one you are looking for

Set objDomain = GetObject("WinNT://domainname,domain")
objDomain.Filter = Array("user")

For Each aUser In objDomain
aUSer.SID????? not sure what property holds the SID
Next

you can search for available domains via vbs as well, whcih would be your 1st loop i guess with the for each auser being nested in that
 
I can't find the property to display the SID. It doesn't seem to be <b>.SID</b> (this spawns an invalid property error). I tried <b>.ObjectSID</b> as well, which doesn't generate an error, but only displays <b>?</b> when I <b>wscript.echo</b> it.
 
Krinid,
Where are you getting the SID from that you need to match up to a user.

Taking a stab in the dark, I am going to guess you are looking in the registry or a workstation?

If so you can match up the SID with the profile diretory which will tell you the user ID.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\SID\ProfileImagePath

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Mark,
I'm getting the SID from the foreign policy; when I query a WinNT object in an LDAP group, it only gives me the SID. (User name, description, adspath, etc - everything is either blank or it shows as the SID). (I don't know why it acts this way, and I don't have the option of changing the system.) So unfortunately, all the info I have is the SID.
 
there is a custom WinNT provder user class property

IADsUser::ObjectSID

it returns an Octet String and can be accessed through the Get method of the IADs interface...i.e. using hte WinNT provider
 
It's right foreign domain with no trust or NT4 domain or Exch-5.5 use the SID-property to bind accounts together.

There is a way.....
But you need to know the group-name and the domain.
It's just a little bit tricky but I'll help you on your way
Also a little bit timeconsuming, but.......
Code:
str_SID = "S-xxxx-xxxx..."
strDom = "ICFUC"
strGrp = "GroupName"

Call fnEnumGroups(strDom, strGrp, str_SID)

Function fnEnumGroups(strDomain, strGroupName, strSID_2_Search)

	Dim objGrp, objUser, intUserSID 
	Set objGrp = GetObject("WinNT://" & strDomain & "/" & strGroupName & ",group")
		objGrp.Filter = Array("user")
		For Each objUser In objGrp
			objUser.GetInfo
			intUserSID = fnGet_HexString(objUser.Get("objectSID"))
			If intUserSID = strSID_2_Search Then
				Wscript.Echo intUserSID
				Wscript.Echo objUser.Name 'or whatever attribute you may need....
				Wscript.Echo ""
				Exit Function
			End if
		
		Next
	Wscript.Echo "Nothing found on : " & strSID_2_Search & " in " & strDomain & "/" & strGroupName
	Set objGrp = Nothing	
End Function

Function fnGet_HexString(intSID)
	Dim strRet, i, b
	strRet = ""
 	For i = 0 to Ubound(intSID)
		b = hex(ascb(midb(intSID,i+1,1)))
		If( len(b) = 1 ) then b = "0" & b
   		strRet = strRet & b
	Next
	
	fnGet_HexString = fnHexStrToDecStr(strRet)
	
End Function

Function fnHexStrToDecStr(strSid) 
 
Dim arrbytSid, lngTemp, j 

ReDim arrbytSid(Len(strSid)/2 - 1) 
For j = 0 To UBound(arrbytSid) 
	arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2)) 
Next 

fnHexStrToDecStr = "S-" & arrbytSid(0) & "-" _ 
& arrbytSid(1) & "-" & arrbytSid(8) 

lngTemp = arrbytSid(15) 
lngTemp = lngTemp * 256 + arrbytSid(14) 
lngTemp = lngTemp * 256 + arrbytSid(13) 
lngTemp = lngTemp * 256 + arrbytSid(12) 

fnHexStrToDecStr = fnHexStrToDecStr & "-" & CStr(lngTemp) 

lngTemp = arrbytSid(19) 
lngTemp = lngTemp * 256 + arrbytSid(18) 
lngTemp = lngTemp * 256 + arrbytSid(17) 
lngTemp = lngTemp * 256 + arrbytSid(16) 

fnHexStrToDecStr = fnHexStrToDecStr & "-" & CStr(lngTemp) 

lngTemp = arrbytSid(23) 
lngTemp = lngTemp * 256 + arrbytSid(22) 
lngTemp = lngTemp * 256 + arrbytSid(21) 
lngTemp = lngTemp * 256 + arrbytSid(20) 

fnHexStrToDecStr = fnHexStrToDecStr & "-" & CStr(lngTemp) 

lngTemp = arrbytSid(25) 
lngTemp = lngTemp * 256 + arrbytSid(24) 

fnHexStrToDecStr = fnHexStrToDecStr & "-" & CStr(lngTemp) 

End Function

Try this, I couldn't myself until tomorrow

Best Regards / ICFUC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top