Reputation: 1739
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
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
Upvotes: 2
Views: 3688
Reputation: 35696
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.
Upvotes: 2