Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess you need to create the user first before setting properties to it, I usually do it by</p> <pre><code>/// &lt;summary&gt; /// This Method will Create a new User Directory Object based on a Username and LDAP Domain /// &lt;/summary&gt; /// &lt;param name="sUserName"&gt;The Username of the New User&lt;/param&gt; /// &lt;param name="sLDAPDomain"&gt;The LDAP Domain for the New User&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public DirectoryEntry CreateNewUser(string sUserName, string sLDAPDomain) { //Set the LDAP qualification so that the user will be Created under the Users Container string LDAPDomain = "/CN=Users," + sLDAPDomain; oDE = new DirectoryEntry("LDAP://" + sADServer + "/" + sLDAPDomain, sADUser, sADPassword, AuthenticationTypes.Secure); oDEC = oDE.Children.Add("CN=" + sUserName, "user"); oDE.Close(); return oDEC; } </code></pre> <p>then set any properties I need</p> <pre><code>/// &lt;summary&gt; /// This will Set the Property of the Directory Entry Object /// &lt;/summary&gt; /// &lt;param name="oDE"&gt;The Directory Object to Set to&lt;/param&gt; /// &lt;param name="sPropertyName"&gt;The Property Name&lt;/param&gt; /// &lt;param name="sPropertyValue"&gt;The Property Value&lt;/param&gt; public void SetProperty(DirectoryEntry oDE, string sPropertyName, string sPropertyValue) { //Check if the Value is Valid if (sPropertyValue != string.Empty) { //Check if the Property Exists if (oDE.Properties.Contains(sPropertyName)) { oDE.Properties[sPropertyName].Value = sPropertyValue; oDE.CommitChanges(); oDE.Close(); } else { oDE.Properties[sPropertyName].Add(sPropertyValue); oDE.CommitChanges(); oDE.Close(); } } } </code></pre> <p>then set the password</p> <pre><code>/// &lt;summary&gt; /// This Method will set the Users Password based on Directory Entry Object /// &lt;/summary&gt; /// &lt;param name="oDE"&gt;The Directory Entry to Set the New Password&lt;/param&gt; /// &lt;param name="sPassword"&gt;The New Password&lt;/param&gt; /// &lt;param name="sMessage"&gt;Any Messages catched by the Exception&lt;/param&gt; public void SetUserPassword(DirectoryEntry oDE, string sPassword, out string sMessage) { try { //Set The new Password oDE.Invoke("SetPassword", new Object[] { sPassword }); sMessage = ""; oDE.CommitChanges(); oDE.Close(); } catch (Exception ex) { sMessage = ex.InnerException.Message; } } </code></pre> <p>And finally enable the account</p> <pre><code>/// &lt;summary&gt; /// This Method will Enable a User Account Based on the Directory Entry Object /// &lt;/summary&gt; /// &lt;param name="oDE"&gt;The Directoy Entry Object of the Account to Enable&lt;/param&gt; public void EnableUserAccount(DirectoryEntry oDE) { oDE.Properties["userAccountControl"][0] = ADMethods.ADAccountOptions.UF_NORMAL_ACCOUNT; oDE.CommitChanges(); oDE.Close(); } </code></pre> <p>For a full implementation you can go here -> <a href="http://anyrest.wordpress.com/2010/02/01/active-directory-objects-and-c/" rel="nofollow">http://anyrest.wordpress.com/2010/02/01/active-directory-objects-and-c/</a></p>
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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