Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess denied when trying to add Windows User account
    primarykey
    data
    text
    <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>
    singulars
    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.
 

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