Creating a Contact in Active Directory
Topic Last Modified: 2006-06-11
Creating a contact involves setting informational properties and saving the contact to Active Directory.
The LDAP URL consists of prefixes and distinguishing names for the contact that address its placement in Active Directory's hierarchy. Use the prefix CN for common names, DC for domains, and O or OU for organizations to refer to the object.
CN is used to uniquely identify the object s common name, as well as to indicate its classification, such as users.
Use as many DCs as necessary for each qualification in the domain name, including a DC for sub-domains.
Example LDAP URL for a Person Object
If James Smith is a person with a Microsoft Exchange mailbox in the domain named somewhere.example.com, and the name of the Exchange Server 2007 is the server, then the LDAP URL would be:
LDAP://theserver/cn=jamessmith,cn=users,dc=somewhere,dc=example,dc=com
Example
The following example creates a contact using the CDO Person object and saves it to Active Directory.
Example
Visual Basic
Dim oPerson As New CDO.Person
Dim strURL As String
oPerson.FirstName = "John"
oPerson.LastName = "Smith"
oPerson.HomeCity = "Redmond"
oPerson.HomeState = "Washington"
oPerson.Email = "jsmith@somewhere.example.com"
oPerson.Fields("objectClass").Value = "contact"
oPerson.Fields.Update
strURL = "LDAP://theserver/cn=johnsmith,cn=users,dc=somewhere,dc=example,dc=com"
'Save the contact
oPerson.DataSource.SaveTo strURL
By default, the CDO person creates a user. In the preceding code, the oPerson.Fields("objectClass").Value is set to type "contact" to create a contact.
The objectClass value is an array of variants, however the property can accept a single value. Thus, the value might be one of the following:
oPerson.Fields("objectClass").Value = "contact"
oPerson.Fields("objectClass").Value = Array("top", "person", "organizationalPerson", "contact")