首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UserPrincipal SetPassword -找不到网络路径

UserPrincipal SetPassword -找不到网络路径
EN

Stack Overflow用户
提问于 2017-11-07 15:19:53
回答 1查看 656关注 0票数 0

我试图使用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)

有什么想法吗?这可能是权限问题吗?

代码语言:javascript
复制
    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)
    {

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-21 16:32:42

因此,显然SetPassword需要端口445,而简单地访问用户数据就不需要。允许这个端口修复了问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47161414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档