修改域中用户密码

时间: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();
        }

修改域中用户密码,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!