Search code examples
c#windowspropertiesaccounts

Change local windows user properties using C#


I am looking for a simple method to modify a local user's properties in windows 7 using a simple c# application.

I am not familiar with many of the Windows system libraries and am looking to accomplish each of the following tasks:

  1. Enable/Disable a local user account in windows.
  2. Change the password of a local user account in windows.

Some example code and an simple explanation of what the code does would be very helpful.

Edit:

I will have administrative access to the machine when this program is going to be run.


Solution

  • If you have access this will give you access to what you need.

    DirectoryEntry localDirectory = new DirectoryEntry("WinNT://"Environment.MachineName.ToString());
    DirectoryEntries users = localDirectory.Children;
    DirectoryEntry user = users.Find("userName");
    

    Here is a link to the docs..

    http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx