C#调用ActiveDirectory的SetPassword函数的问题

时间:2011-05-19 09:46:59

标签: c# active-directory

我成功创建了一个新用户,然后尝试使用以下代码设置其初始密码:

newUser.AuthenticationType = AuthenticationTypes.Secure;
newUser.Invoke("SetPassword", new object[] { "somepassword" });
newUser.Properties["LockOutTime"].Value = 0; //unlock account

当它(最终)返回时,我得到以下异常

System.IO.FileNotFoundException: The network path was not found

如果我检查'newUser'对象,它有一个Path属性,对我来说很好。

我不认为我的AD实例可以通过SSL使用,我只能通过端口389连接到它。这与它有关吗?

任何帮助表示赞赏,我是AD的新手并且正在努力......

由于

1 个答案:

答案 0 :(得分:2)

根据建议here,您可能会在新的System.DirectoryServices.AccountManagement命名空间中获得更多成功。

// establish context for local machine 
PrincipalContext ctx = new PrincipalContext(ContextType.Machine);

// find the account
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "YourUser");

// set the password to a new value 
user.SetPassword("new-top-secret-password"); 
user.Save();

marc_s在OP中提供了更多详细信息。