Dionysus
Dionysus

Reputation: 41

Reset password on Windows Server 2008 R2

We have an Employee Self Service application running on standalone server. One of the feature of the application is "forgotten password", so employees can reset their own passwords. It works fine an all servers, but not on Windows Server 2008 R2. Below is a fragment of code we use:

User.Invoke("SetPassword", new object[] {"#12345Abc"});
User.CommitChanges();

It looks like it is not possible to make it work in Windows Server 2008 R2 at all. If someone has it works, please help.

Thanks

Upvotes: 3

Views: 1669

Answers (2)

Dionysus
Dionysus

Reputation: 41

We also tried this one:

PrincipalContext context = new PrincipalContext(ContextType.Machine, "servername");

UserPrincipal up = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "username");
if (up != null)
{
    up.SetPassword("newpassword");
    // We got the same access denied exception here
    up.Save();
}

Upvotes: 1

fejesjoco
fejesjoco

Reputation: 11903

Try UserPrincipal.SetPassword. It's a higher level abstraction and thus smarter. It will know what lower level function to call. The invoke way seems way too fragile to me.

Upvotes: 1

Related Questions