Trying to search Active Directory - getting "Server Is Not Operational"

chris128

New member
Joined
Dec 13, 2007
Messages
2
Programming Experience
Beginner
Hi Everyone,

I'm fairly new to VB.NET so sorry if I use the wrong terminoligy sometimes. Basically I am trying to do something fairly simple - get the full distinguished name (aka full path) of a user account from Active Directory by searching for a user account name.

Here is the code I have written so far:

In My Module:
VB.NET:
        Try
            Dim RootDSE As DirectoryEntry
            Dim ADSearcher As DirectorySearcher
            Dim ADObject As SearchResult
            RootDSE = New DirectoryEntry("LDAP://rootDSE")
            ADSearcher = New DirectorySearcher(RootDSE)
            ADSearcher.SearchScope = SearchScope.Subtree
            ADSearcher.Filter = ("(&(ObjectClass=User)(sAMAccountName=chris))")

            For Each ADObject In ADSearcher.FindAll
                GetUserForm.DNbox.AppendText("CN= " & ADObject.Properties("cn").Item(0) & vbNewLine)
                     Next
        Catch e As Exception
            MessageBox.Show(e.Message & " " & e.ToString)
        End Try

NOTE: this isnt trying to get the DN from the user account, this is purely trying to retrieve the "cn" attribute from whatever accounts have been found by the search for "chris" in the sAMAccountName field..but I cant even get this to work so I havent gone any further yet.
Should I jsut be connecting to LDAP://rootDSE like I have done or should I be getting the user to enter the domain name or a DC server name and passing that to the LDAP:// string?

Anyways, when I run that, it throws an exception saying "Server Is Not Operational."

Any help appreciated,
Cheers
Chris
 
OK so I think there were two main causes of my problems.

1. I was testing on a VmWare server and VmWare Workstation and the virtual images I was using were fairly old cos I couldnt be bothered to rebuild a server 2003 and XP machine so they had been messed around with a lot before. I think the workstation had been joined to about 8 domains in the course of its lifetime, although this shouldnt really make a difference but when I tested on a real server and workstation it worked fine after I did this:
2. Changed RootDSE = New DirectoryEntry("LDAP://rootDSE")
to
Changed RootDSE = New DirectoryEntry()

Hope that helps someone in the future!
 
Back
Top