Change windows user account password

  • Thread starter Thread starter Srikanth
  • Start date Start date
S

Srikanth

Hi All,



Can any one tell me how to change windows user account password
by programmatically using C#? I don't have administrator privileges and I
want to change my account password by programmatically.



I will be thankful if you can provide a sample program.



Thanks in Advance,

Srikanth
 
You can't call SetPassword if you are not an administrator! And that's what
OP said isn't it?

Willy.
 
Srikanth said:
Hi All,



Can any one tell me how to change windows user account password
by programmatically using C#? I don't have administrator privileges and I
want to change my account password by programmatically.



I will be thankful if you can provide a sample program.



Thanks in Advance,

Srikanth

Use the System.DirectoryServices to change the password of a local user
account.

Something like this will do.

using System;
using System.DirectoryServices;
// correct the userPath!!!
string userPath = "WinNT://yourMachineName/someuser";
using (DirectoryEntry userEntry = new DirectoryEntry(userPath))
{
object[] password = new object[] {"newPwd", "oldPwd"};
object ret = userEntry.Invoke("ChangePassword", password );
userEntry.CommitChanges();
}

Willy.
 
Back
Top