嗨,我正在尝试重置 Active Directory 用户的密码,但出现错误,以下是我的代码:
public string ChangePassword(string Identity,string OldPassword, string Password)
{
string success = "Success";
try
{
DirectoryEntry UserEntry = null;
DirectoryEntry entry = new DirectoryEntry("LDAP://.../DC=Domain,DC=COM", Identity, OldPassword);
DirectorySearcher search = new DirectorySearcher(entry);
SearchResult resultsearch = search.FindOne();
if (resultsearch == null)
{
success = "User Not Found In This Domain";
}
else
{
success = "find";
UserEntry = resultsearch.GetDirectoryEntry();
UserEntry.Username = @"Domain\Administrator";
UserEntry.Password = "password";
UserEntry.AuthenticationType = AuthenticationTypes.None;
if (UserEntry == null)
success = "User Not Found In This Domain";
else
{
try
{
success = UserEntry.Username.ToString();
UserEntry.Invoke("ChangePassword", new object[] { OldPassword, Password });
UserEntry.CommitChanges();
}
catch (Exception ex)
{
success = ex.ToString();
}
}
}
}
catch (Exception ex)
{
success = ex.ToString();
}
所以我在UserEntry.Invoke("ChangePassword", new object[] { OldPassword, Password });中遇到错误 UserEntry.CommitChanges();
错误:
System.Runtime.InteropServices.COMException (0x80020006): Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
at WebService.ChangePassword(String Identity, String OldPassword, String Password) in c:\inetpub\wwwroot\WebSite1\App_Code\WebService.cs:line 370