C#修正及重置電腦暗碼DirectoryEntry完成辦法。本站提示廣大學習愛好者:(C#修正及重置電腦暗碼DirectoryEntry完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#修正及重置電腦暗碼DirectoryEntry完成辦法正文
本文實例講述了C#修正及重置電腦暗碼DirectoryEntry完成辦法。分享給年夜家供年夜家參考。詳細以下:
C#修正電腦暗碼辦法以下:
/// <summary> /// 更改Windows帳戶暗碼 /// </summary> /// <param name="username"></param> /// <param name="oldPwd"></param> /// <param name="newPwd"></param> public static void ChangeWinUserPasswd(string username, string oldPwd, string newPwd) { try { 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(); } catch (Exception) { } }
C#重置電腦暗碼:
/// <summary> /// 重置指定用戶的暗碼 /// </summary> /// <param name="userName">用戶名</param> /// <param name="password">新暗碼</param> public static void ResetUserPassword(string userName, string password) { string _Path = "WinNT://" + Environment.MachineName; DirectoryEntry machine = new DirectoryEntry(_Path); //取得盤算機實例 DirectoryEntry user = machine.Children.Find(userName, "User"); //找得用戶 if (user != null) { user.Invoke("SetPassword", password); //用戶暗碼 user.CommitChanges(); } }
願望本文所述對年夜家的C#法式設計有所贊助。