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:
- Enable/Disable a local user account in windows.
- 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.
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
I have had a really great experience using the System.DirectoryServices.AccountManagement namespace. It lets you do all the stuff you want to do with accounts without needing to mess with magic strings.
System.DirectoryServices.AccountManagement namespace: http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx
The key entry point to look at is the PrincipalContext class.
精彩评论