Platform SDK: Active Directory, ADSI, and Directory Services

Creating a User

To add a user to Active Directory™, you create a user object in the domain container of the domain where you want to place the user. Users can be created at the root of the domain, within an organizational unit, or within a container.

When you create a user object, you must also set the following attributes to make the object a legal user that is recognized by Active Directory and the Windows® Security system:

cn
Required. Specify the name of the user object in the directory. This will be the object's relative distinguished name (RDN) within the container where you create the user.
sAMAccountName
Required. Specify a string that is the name used to support clients and servers from a previous version of Windows®. The sAMAccountName should be less than 20 characters to support clients from a previous version of Windows.

The sAMAccountName must be unique among all security principal objects within the domain. You should perform a query against the domain to verify that the sAMAccountName is unique within the domain.

Optionally, you can also set other properties. The following user properties are set with default values if you do not explicitly set them at creation time:

Property Value
accountExpires Default is Never.
cn Specified in IADsContainer::Create.
nTSecurityDescriptor A security descriptor is created based on the rules specified in How Security Descriptors are Set on New Directory Objects.
objectCategory Person
name RDN is the cn.
pwdLastSet Controls whether user must change password at next logon.

Default is 0. Zero (0) means the user must change the password at next logon.

UserAccountControl Contains values that determine several logon and account features for the user.

By default, the following flags are set:

UF_ACCOUNTDISABLE
UF_PASSWD_NOTREQD
UF_NORMAL_ACCOUNT

UF_ACCOUNTDISABLE means the user's account is disabled. UF_PASSWD_NOTREQD means no password is required for the user to log on. UF_NORMAL_ACCOUNT is a default account type that represents a typical user.

memberOf Domain Users