Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / October 2004

Tip: Looking for answers? Try searching our database.

Active Directory new User account - howto set CN value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Publickey - 22 Oct 2004 05:45 GMT
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?
publickey - 22 Oct 2004 06:01 GMT
Problem solved.  I actually assigned the CN value to sAMAccountName while
creating the user object.  :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.