Using the Windows net command, it’s easy to create local Windows User Accounts. The syntax for the net command is:
net user [username] [password] /ADD
The following C# function takes in three parameters -- username, password and home directory.
using System.Diagnostics;
public void CreateLocalUser(string username, string password, string homedir)
{
if (!Directory.Exists(homedir))
Directory.CreateDirectory(homedir);
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = "C:/WINNT/SYSTEM32";
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = @" user " + username + @" " + password + @" /ADD /ACTIVE:YES " +
@"/EXPIRES:NEVER /FULLNAME:" + username + @" /HOMEDIR:""" +
homedir + @""" /PASSWORDCHG:NO /PASSWORDREQ:YES";
MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
使用c#创建windows本地用户帐号
最新推荐文章于 2022-01-16 17:14:32 发布