title: Active Directory LDAP - Lock User Account
body: <p>What is the best way to use System.DirectoryServices.AccountManagement to lock an Active Directory user object? I'm able to determine if an account is locked using..</p>
  
  <pre><code>UserPrincipal principal = new UserPrincipal(context);
  bool locked = principal.IsAccountLockedOut();
  </code></pre>
  
  <p>How do I lock the account? Is there an alternative to doing something like this...</p>
  
  <pre><code>UserPrincipal principal = new UserPrincipal(context);
  DirectoryEntry entry = (DirectoryEntry)principal.GetUnderlyingObject();
  
  int val = (int)entry.Properties["userAccountControl"].Value;
  
  entry.Properties["userAccountControl"].Value = val | 0x0010;
  entry.CommitChanges();
  </code></pre>