title: Access denied when trying to add Windows User account
body: <p>I am trying to programmatically add a user like this below but get an access denied message on the Save. I'm running locally on Windows 7 and the code resides in a console app.</p>
  
  <pre><code>/// &lt;summary&gt;
  /// 
  /// &lt;/summary&gt;
  /// &lt;param name="userName"&gt;&lt;/param&gt;
  /// &lt;param name="password"&gt;&lt;/param&gt;
  /// &lt;param name="description"&gt;&lt;/param&gt;
  public static void CreateUser(string userName, string password, string description)
  {
      PrincipalContext pc = new PrincipalContext(ContextType.Machine, null);
      System.DirectoryServices.AccountManagement.UserPrincipal u = new UserPrincipal(pc);
      u.SetPassword(password);
      u.Name = userName;
      u.Description = description;
      u.UserCannotChangePassword = true;
      u.PasswordNeverExpires = true;
      u.Save();
  
      GroupPrincipal gp = GroupPrincipal.FindByIdentity(pc, "Users");
      gp.Members.Add(u);
      gp.Save();
  }
  </code></pre>
  
  <p>Any ideas? I tried supplying an administrators username and password and still get the same error.</p>
  
  <p>The console app gets executed like this:</p>
  
  <pre><code> ProcessStartInfo startInfo = new ProcessStartInfo();
                      startInfo.UserName = userName;
                      startInfo.Password = securePassword;
                      startInfo.LoadUserProfile = true;
                      startInfo.UseShellExecute = false;
                      startInfo.FileName = batchPath;
                      startInfo.Arguments = operationLogID.ToString();
                      Process.Start(startInfo);
  </code></pre>
  
  <p>Here is a rough view of how the code is set up:</p>
  
  <ul>
  <li>Console App test harness gets executed in debug mode.</li>
  <li>I check for a user and if they don't exist..then I try and create it shown above. This is where the error occurs.</li>
  </ul>