static void Main(string[] args) { //string path = @"LDAP://CN=sp\administrator"; string username = "administrator"; string password = "6yhn^YHN"; string newPwd = "7ujm&UJM"; //DirectoryEntry de = new DirectoryEntry(path, username, password); //de.Invoke("ChangePassword", new object[] { password, newPwd }); //de.CommitChanges(); ChangeWinUserPasswd(username,password ,newPwd); } public static void ChangeWinUserPasswd(string username, string oldPwd, string newPwd) { DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer"); DirectoryEntry user = localMachine.Children.Find(username, "user"); object[] password = new object[] { oldPwd, newPwd }; object ret = user.Invoke("ChangePassword", password); user.CommitChanges(); localMachine.Close(); user.Close(); }
原文地址:http://blog.csdn.net/u014316433/article/details/28394129