Click here to Skip to main content
16,021,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a program to list computers to my listview in Active Directory in Visual Basic. After the form loads I receive the error message that states "DirectoryServicesCOMException - An operations error occured" The line of code this happens on is
For Each dirSearchResults In dirSearcher.FindAll()

Any help is appreciated.
VB
Dim dirEntry1 As DirectoryEntry = New DirectoryEntry("LDAP://DC01/CN=Computers/DC=TEST/DC=COM")
        Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry1)
        dirSearcher.Filter = ("(objectCategory=Computer)")
        Dim dirSearchResults As SearchResult
        ' 3. Loop through all the computer names returned
        For Each dirSearchResults In dirSearcher.FindAll()
            ListView1.Items.Add(dirSearchResults.GetDirectoryEntry().Name.ToString)
        Next
    End Sub
Posted

That's because the current user running this code is either not a domain user or does not have permission to look up AD.
To solve this issue, either run this code as a domain user or specify explicitly credentials
in your DirectoryEntry constructor.
 
Share this answer
 
Comments
tupacIT 10-Feb-11 10:37am    
Thanks I have created my DirectoyEntry constructor below does this look right if so I am still getting the error

Public Shared Function GetDirectoryEntry() As DirectoryEntry
Dim dirEntry As DirectoryEntry = New DirectoryEntry
dirEntry.Path = "LDAP://Test/CN=Computers/DC=COM"
dirEntry.Username = "TEST\user"
dirEntry.Password = "password"
Return dirEntry
End Function
Do you have permission to access AD? You can specify username password of administrator in DirectoryEntry constructor. Post errorcode, extendederror; so that others can help you in right direction.
 
Share this answer
 
Comments
tupacIT 10-Feb-11 9:45am    
Thanks I have permissions but I did not specify permissions in my DirectoryEntry constructor I will try to lookup the proper DirectoryEntry constructor and see if that works. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900