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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Querying Active Directory for Group and Username

Status
Not open for further replies.

eyorre

Programmer
Jan 24, 2002
32
GB
I've been looking around various threads on this site and found a lot of useful stuff regarding querying Active Directories but I am still having problem getting my code to work.

It is not finding the username within the group when I would expect it to. I'm not sure how to find out the username from the AD so I have pulled in the username string using the request.servariables("LOGON_USER") method but maybe that is wrong?

Can anyone see where I am going wrong with this please?

Code:
strNetworkID = Request.ServerVariables("LOGON_USER")

Dim oGroup, sGroup, oUser, sUser
    'Query AD
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =   CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"

sUser=right(strNetworkID,instr(strNetworkID,"\")+2)
Set oUser = GetObject("WinNT://myDomain/" & sUser & ",user")
sGroup = "myGroup"
Set oGroup=GetObject("WinNT://myDomain/" &  sGroup & ",group")

IF oGroup.IsMember(oUser.aDSPath) then
	response.write "User is a member of the group"
end if
 
First thing I would try is add:
Response.Write "sUser = " & sUser

Just to see what you've got in that variable... I'd be worried that the Right(Instr()) bit was backwards.
 
Thanks for this suggestion Sheco. I've tried response.write and it is picking up sUser ok.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top