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!

Active Directory Query - Input directory, Output usernames

Status
Not open for further replies.
Apr 9, 2002
102
US
A colleague has developed the following code, but I wanted to adapt it to pull a little different information. I wanted to be able to input a directory name (instead of the user group) and get all the users who have access to that directory. An additional plus would be to also select the type of file access the users have within the directory. Here is the code:

Function GetObjectDN(strAccount)
Dim objConnection, objCommand, objRecordSet

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT AdsPath, distinguishedName, objectClass " & _
"FROM 'LDAP://DC=company,DC=com' WHERE " & _
" objectClass='group' AND " & _
" samAccountName='" & strAccount & "'"

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = 2 ' ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

If objRecordSet.EOF Then
GetObjectDN = ""
Else
Dim x
GetObjectDN = objRecordSet.fields("AdsPath")
End If

objConnection.Close
End Function

Any help you can provide would be much appreciated. Thanks.

Marrow
 
I don't have an answer, but a direction that might help.

Add a reference to Active DS Type Library (activeds.tlb) to your project. This will expose the Active Directory object model for you.

It's been a while since I done this but I believe you will need to get a list of the Group(s) ([tt]IADsGroup[/tt]) that have rights to a resource, then return the [tt]Members()[/tt] of that group.

Hope this helps,
CMP

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top