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?
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