开发者

Problem with C# calling ActiveDirectory's SetPassword function

开发者 https://www.devze.com 2023-03-06 19:34 出处:网络
I create a new user successfully, and then I try to set their initial password using the following code:

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[] { "som开发者_JS百科epassword" });
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

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

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?

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

Thanks


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 provides more detail in the OP.

0

精彩评论

暂无评论...
验证码 换一张
取 消