Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Read this excellent CodeProject article</p> <p><a href="http://www.codeproject.com/KB/system/everythingInAD.aspx" rel="nofollow noreferrer"><strong>Howto: (Almost) Everything In Active Directory via C#</strong></a></p> <p>There is a section "Create User Account" and "Dealing with User Passwords".</p> <p><strong>UPDATE:</strong></p> <p><em>To adapt the code for local accounts replace the respective lines with these:</em></p> <pre><code>DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName); DirectoryEntry newUser = localMachine.Children.Add("localuser", "user"); </code></pre> <p><em>Here starts the original code snippet for domain accounts:</em></p> <pre><code>public string CreateUserAccount(string ldapPath, string userName, string userPassword) { string oGUID = string.Empty; try { string connectionPrefix = "LDAP://" + ldapPath; DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix); DirectoryEntry newUser = dirEntry.Children.Add ("CN=" + userName, "user"); newUser.Properties["samAccountName"].Value = userName; int val = (int)newUser.Properties["userAccountControl"].Value; newUser.Properties["userAccountControl"].Value = val | 0x10000; newUser.CommitChanges(); oGUID = newUser.Guid.ToString(); newUser.Invoke("SetPassword", new object[] { userPassword }); newUser.CommitChanges(); dirEntry.Close(); newUser.Close(); } catch (System.DirectoryServices.DirectoryServicesCOMException E) { //DoSomethingwith --&gt; E.Message.ToString(); } return oGUID; } </code></pre> <blockquote> <p>There are some specifics to understand when dealing with user passwords and boundaries around passwords such as forcing a user to change their password on the next logon, denying the user the right to change their own passwords, setting passwords to never expire, to when to expire, and these tasks can be accomplished using UserAccountControl flags that are demonstrated in the proceeding sections.</p> <p>Please refer to this great <a href="http://msdn.microsoft.com/en-gb/library/ms180915.aspx" rel="nofollow noreferrer">MSDN article: Managing User Passwords</a> for examples and documentation regarding these features.</p> </blockquote> <pre><code>CONST HEX ------------------------------------------ SCRIPT 0x0001 ACCOUNTDISABLE 0x0002 HOMEDIR_REQUIRED 0x0008 LOCKOUT 0x0010 PASSWD_NOTREQD 0x0020 PASSWD_CANT_CHANGE 0x0040 ENCRYPTED_TEXT_PWD_ALLOWED 0x0080 TEMP_DUPLICATE_ACCOUNT 0x0100 NORMAL_ACCOUNT 0x0200 INTERDOMAIN_TRUST_ACCOUNT 0x0800 WORKSTATION_TRUST_ACCOUNT 0x1000 SERVER_TRUST_ACCOUNT 0x2000 DONT_EXPIRE_PASSWORD 0x10000 MNS_LOGON_ACCOUNT 0x20000 SMARTCARD_REQUIRED 0x40000 TRUSTED_FOR_DELEGATION 0x80000 NOT_DELEGATED 0x100000 USE_DES_KEY_ONLY 0x200000 DONT_REQ_PREAUTH 0x400000 PASSWORD_EXPIRED 0x800000 TRUSTED_TO_AUTH_FOR_DELEGATION 0x1000000 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload