C#调用ActiveDirectory的SetPassword函数的问题 [英] Problem with C# calling ActiveDirectory's SetPassword function

查看:92
本文介绍了C#调用ActiveDirectory的SetPassword函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I create a new user successfully, and then I try to set their initial password using the following code:

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

(最终)返回时,出现以下异常

When it (eventually) returns, I get the following exception

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

如果我检查了'newUser'对象,它的Path属性对我来说很好。

If I inspect the 'newUser' object, it has a Path attribute which looks fine to me.

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

I don't think my instance of AD is available over SSL though, I can only connect to it over port 389. Is that something to do with it?

感谢任何帮助,我AD的新手和挣扎中...

Any help appreciated, I'm new to AD and struggling...

谢谢

推荐答案

建议在此处,新的和改进的 System.DirectoryServices.AccountManagement 命名空间获得了更大的成功。

As suggested here, you might have more success with the new and improved System.DirectoryServices.AccountManagement namespace.

// 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中提供了更多详细信息。

marc_s provides more detail in the OP.

这篇关于C#调用ActiveDirectory的SetPassword函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆