Hi, I am having trouble setting the user's cn value using VB .NET 2002 while creating a new user account. The code is as below: ***********************Start of code**************************** Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://" + ldapStr) Dim NewUser As DirectoryEntry = enTry.Children.Add("CN=" & sAMAccountName, "User") NewUser.Properties("sAMAccountName").Value = sAMAccountName NewUser.Properties("Description").Add("Student imported on " + Date.Now) NewUser.Properties("mail").Add(mail) NewUser.Properties("displayName").Add(givenName + " " + sn) NewUser.Properties("cn").Add(givenName + " " + sn) NewUser.Properties("name").Add(givenName + " " + sn) NewUser.Properties("homeDirectory").Add(homeDirectory) NewUser.Properties("homeDrive").Add(homeDrive) NewUser.Properties("mobile").Add(mobile) NewUser.Properties("telephoneNumber").Add(telephoneNumber) NewUser.Properties("sn").Add(sn) NewUser.Properties("givenName").Add(givenName) NewUser.Properties("scriptPath").Add("students.bat") NewUser.CommitChanges() NewUser.Invoke("SetPassword", New Object() {password}) NewUser.CommitChanges() **************************End of ************************* Error message "Additional information: An invalid dn syntax has been specified" poped up and stopped at the first CommitChanges method. No error message shown if I commented the set cn line. However, it is not what I wanted as it will use the sAMAccountName for cn while I want to use the user's full name as cn. How can I set the cn value?
Problem solved. I actually assigned the CN value to sAMAccountName while creating the user object. :)
Don't see what you're looking for? Try a search.
|