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 =