111,129
社区成员
发帖
与我相关
我的任务
分享
public static bool ChangePwd(string UserName, string oldPwd, string newPwd)
{
try
{
DirectoryEntry MachineDirectoryEntry;
MachineDirectoryEntry = new DirectoryEntry("WinNT://" + System.Environment.MachineName);
DirectoryEntry CurrentDirectoryEntry = MachineDirectoryEntry.Children.Find(UserName);
CurrentDirectoryEntry.Invoke("ChangePassword", new Object[] { oldPwd, newPwd });
CurrentDirectoryEntry.CommitChanges();
CurrentDirectoryEntry.Close();
return true;
}
catch (Exception exp)
{
if (exp.InnerException.Message.Replace("'", "").IndexOf("网络密码不正确") != -1)
throw new Exception("密码修改失败,输入的原始密码不正确");
else
throw new Exception(exp.InnerException.Message);
}
finally
{
}
}