On a Vista dev machine, I successfully used this code to change the password for the Administrator user:
directoryEntry.Invoke("SetPassword", "new");
When I moved it to my Dev 2008 machine, this code did not work, and I was forced to use the following code:
directoryEntry.Invoke("ChangePassword", new object[] { "old", "new" });
My question is why?
In both cases, I created a DirectoryEntry object as such:
DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username));
Thanks! 8)
In case you guys find this useful, this is real 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 name: " + machineName); ResetPassword(machineName, "Administrator", "new");
c # change-password active-directory directoryservices
sholsapp
source share