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