开发者

Change local windows user properties using C#

开发者 https://www.devze.com 2023-02-17 06:11 出处:网络
I am looking for a simple method to modify a local user\'s properties in windows 7 using a simple c# application.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消