Use the DirectoryEntry class in C # To operate Windows accounts

Source: Internet
Author: User

Using C # To operate windows accounts in the past few days is quite tangled. I have never done it before. google has read a lot of information and tried many methods to solve my problem.

1. Create a windows Account

01 /// <summary> 02 /// Create a Windows Account 03 /// </summary> 04 /// <param name="pathname"></param> 05 /// <returns></returns> 06 public static void CreateLocalUser( string username, string password, string description) 07 { 08      DirectoryEntry localMachine = new DirectoryEntry( "WinNT://" + Environment.MachineName + ",computer" ); 09      var newUser = localMachine.Children.Add(username, "user" ); 10      newUser.Invoke( "SetPassword" , new object [] { password }); 11      newUser.Invoke( "Put" , new object [] { "Description" , description }); 12      newUser.CommitChanges(); 13      localMachine.Close(); 14      newUser.Close(); 15 }

2. Change the Windows Account Password

01 /// <summary> 02 /// Change the Windows Account Password 03 /// </summary> 04 /// <param name="username"></param> 05 /// <param name="oldPwd"></param> 06 /// <param name="newPwd"></param> 07 public static void ChangeWinUserPasswd( string username, string oldPwd, string newPwd) 08 { 09      DirectoryEntry localMachine =
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.