Question Active Directory

igutman

New member
Joined
Jul 18, 2011
Messages
3
Programming Experience
3-5
I want to make a simple code that get username (string),search this user on the ActiveDirectory and put into another string the "Canonical name of object" (inside object catagory)someone can post here this code?TY! :]
 
I already saw this article and try it, but still I didnt success to get a string that contain the "Canonical name of object" or any other stuff that has there into variable.

If someone can post here the code that take the "Canonical name of object" from the AD and put it into string (that I can use it after it) it will be really great!
 
The canonical name is the same information just formatted differently:

The LDAP relative distinguished name uniquely identifies the object within its parent container. For example, the LDAP relative distinguished name of a computer named my computer is CN=mycomputer. Relative distinguished names must be unique in that users cannot have the same name within an organizational unit.

The LDAP distinguished name is globally unique. For example, the distinguished name of a computer named mycomputer in the MyOrganizationalUnit organizational unit in the microsoft.com domain is CN=mycomputer, OU=MyOrganizationalUnit, DC=microsoft, DC=com.

The canonical name is constructed the same way as the distinguished name, but it is represented using a different notation. The canonical name of the computer in the previous example would be Microsoft.com/MyOrganizationalUnit/mycomputer.

taken from: Object names: Active Directory
 
I worte this code:
Public Shared function GetUser (ByVal UserName as String) as DirectoryServices.DirectoryEntry
Dim dirEntry As New DirectoryServices.DirectoryEntry
dirEntry.Path ="LDAP://[IP]/CN=Users;DC=[my network name]"
dirEntryUsername ="[user]"
dirEntry.Password ="[password]"

Dim dirSearch as new DirectoryServices.DirectorySearcher(dirEntry)

dirSearch.Filter =(&(objectCategory=user) (cn=" + UserName +"))"

Dim searchResults as DirectoryServices.SearchResult
searchResults = dirSearch.FindOne
If Not searchResult is nothing then
dirEntry = New DirectoryServices.DirectoryEntry(searchResults.Path)
Return searchResults.GetDirectoryEntry()
Else
Return Nothing
End If
End function
The code stop on : searchResults = dirSearch.FindOne
Error: DirectoryServicesCOMExpeception was unhandled.

What I need to wrote to fix the code?
I need to Get "Canonical name of object" into a string, I put it to EXCEL file after it.
 
Back
Top