Wednesday, August 22, 2012

Update Windows Local Account Password

I would like to enable users to update their account passwords through a Web Part in SharePoint 2010.

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

string userPath = "WinNT://computerName/userName";
DirectoryEntry userEntry = new DirectoryEntry(userPath);
object[] password = {newPassword};
object ret = userEntry.Invoke("SetPassword", password);
userEntry.CommitChanges();

userEntry.Close();

Above snippet code can really update their passwords!

Change local administrator password in C# 

No comments:

Post a Comment