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();
}
修改域中用户密码
最新推荐文章于 2024-05-30 15:18:28 发布