我试图使用System.DirectoryServices.AccountManagement命名空间更改AD用户密码。下面是我的代码,一切似乎都正常,我可以在调用FindByIdentity之后访问用户属性--但是当我试图调用SetPassword时,会引发以下异常:
Exception has been thrown by the target of an invocation. The network path was not found. (Exception from HRESULT: 0x80070035)
有什么想法吗?这可能是权限问题吗?
try
{
string sDomain = "domain";
string sDefaultOU = "defaultOU";
string sServiceUser = "adminUser";
string sServicePassword = "password";
using (var context = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, sServiceUser, sServicePassword))
{
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "accountName"))
{
// I can access the user properties
label.Text = user.EmailAddress;
label.Text = user.LastPasswordSet.ToString();
// But setting the password throws the exception
user.SetPassword("newPassword");
user.Save();
}
}
}
catch (Exception ex)
{
}发布于 2017-11-21 16:32:42
因此,显然SetPassword需要端口445,而简单地访问用户数据就不需要。允许这个端口修复了问题。
https://stackoverflow.com/questions/47161414
复制相似问题