修改域中用户密码
时间:2014-06-07 15:20:59
收藏:0
阅读:275
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(); }
评论(0)