Using Directory Services for LOCAL SYSTEM


I have been given a task to work with windows users through web, task like change password, etc. I tried searching for articles for the same to finish this asap. But it took more time as all articles were referring to active directory and LDAP queries and I want to make changes to local system.


When I have started reading article about changing the windows password or any other such operation through ASP.NET, I got all the answers with LDAP query which is very much true for domain environment. But I don’t have one, I have normal local system on which I have to change the password, etc through C# web page.


Finally I have found some none other then Microsoft links (mentioned in Reference sec.) to tackle this issue. The code was pretty simple, just had to modify the query provided to Directory Services constructor. It was “WinNT://” instead of “LDAP://”.

private bool ResetPassword(string computerName, string username, string newPassword)
	bool isSuccess = false;
		DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username));
		directoryEntry.Invoke("ChangePassword", new object[] { oldpassword.Text.ToString(), newpassword.Text.ToString() });
		isSuccess = true;
	catch (Exception ex) { output.Text = ex.Message.ToString(); }
	return isSuccess;


Using directory services and Visual C#

Creating DirectoryEntry Component Instances

LDAP Query Basics

Other way to reset user password

  • Pingback: Run Code by impersonating user privilege « Dhiraj's Blogs()

  • In his own discussion of how to make great content, successful blogger
    Darren Rowse states that you should make your content scannable.
    You may add your content and write as much as you like,
    but the particular platform has every right to altogether remove ‘your’ blog from
    their system.