Note that there are some explanatory texts on larger screens.

plurals
  1. PODirectoryEntry to change password: Different behavior between Vista/Server2008
    primarykey
    data
    text
    <p>On a Vista dev machine I used this code successfully to change user "Administrator" password:</p> <pre><code>directoryEntry.Invoke("SetPassword", "new"); </code></pre> <p>When I moved it over to my Server 2008 dev machine that code did not work, and I was forced to use the following code:</p> <pre><code>directoryEntry.Invoke("ChangePassword", new object[] { "old", "new" }); </code></pre> <p>My question is, why?</p> <p>For both cases, I created my DirectoryEntry object as such:</p> <pre><code>DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username)); </code></pre> <p>Thanks! 8)</p> <p>In case you guys find it helpful, heres the actual code.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.DirectoryServices; using System.Security.Principal; namespace AccountMod { class Program { static void Main() { Console.WriteLine("Attempting reset...\n"); try { String machineNameAndUser = WindowsIdentity.GetCurrent().Name.ToString(); String machineName = WindowsIdentity.GetCurrent().Name.ToString().Substring(0, machineNameAndUser.IndexOf('\\')); Console.WriteLine("Computer's name: " + machineName); ResetPassword(machineName, "Administrator", "new"); //ChangePassword("Administrator", "current", "new"); Console.WriteLine("Finished..."); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.WriteLine(e.InnerException); } Console.ReadKey(); } public static void ResetPassword(string computerName, string username, string newPassword) { DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username)); directoryEntry.Invoke("SetPassword", newPassword); //directoryEntry.Invoke("ChangePassword", new object[] { "current", "new" }); } } } </code></pre>
    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.
 

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