我使用System.DirectoryServices中的类来更改AD中的密码。代码是这样的:为什么在不同的计算机上使用相同的c#代码在AD中更改密码的速度不同?
DirectoryEntry _directoryEntry = new DirectoryEntry(ldapPath, user, pwd, AuthenticationTypes.Secure);
public bool ChangePassword(string userPath, string newPassword)
{
try
{
if (userPath != null && _directoryEntry != null)
{
_directoryEntry.Path = userPath;
//Set the password
_directoryEntry.Invoke("SetPassword", new object[] { newPassword });
_directoryEntry.CommitChanges();
return true;
}
}
catch (Exception ex)
{
//Invalid Login or the domain controller is not contactable
throw ex;
}
finally
{
_directoryEntry.Close();
_directoryEntry = null;
}
return false;
}
我在不同的计算机上执行这些代码。花费的时间从几毫秒到几秒。
为什么在不同的环境中执行相同的代码在AD中更改密码花费不同的时间?我花了很多时间来处理这个问题,但仍然没有结果。有人可以告诉我吗?非常感谢你!!!!!
我的第一个想法是:不同机器之间的网络拓扑有什么不同?在域控制器上更改AD密码(例如)可能需要的时间比在远离主机的客户端计算机上执行更短的时间。 – ravuya 2012-03-26 05:06:20
部分计算机与AD处于同一网段,其他计算机不在。但是如果电脑可以快速更换AD口令,它可以快速更换不同网段中的任何AD。所以我想也许它不是关于网络拓扑,而是关于计算机上的系统环境。就像其中一台计算机上的某些服务一样,但其他服务却没有。但我找不到任何明显的差异,使一些电脑运行速度快于其他电脑。 @ravuya – Prince 2012-03-26 06:25:39