Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
 
Creating Users 

The following example shows how to create a user in an organizational unit. By default, this account will be disabled. To enable the account, set a password for it. For more information, see Managing User Passwords.

C#
DirectoryEntry ent = new DirectoryEntry();
DirectoryEntry ou = ent.Children.Find("OU=Consulting");

// Use the Add method to add a user to an organizational unit.
DirectoryEntry usr = ou.Children.Add("CN=New User","user");
// Set the samAccountName, then commit changes to the directory.
usr.Properties["samAccountName"].Value = "newuser"; 
usr.CommitChanges();

In this example, the samAccountName attribute is set. For more information about this attrobite, see the topic samAccountName in the MSDN Library at http://msdn.microsoft.com/library.

The samAccountName attribute creates a unique samAccountName, such as $CP2000-O16B1V0UKHK7. This attribute is required on the user account when the domain controller is running on Windows NT Server 4.0. In Windows Server 2003, the samAccountName attribute is optional.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker