您的位置:首页 > 编程语言 > C#

使用c#创建windows本地用户帐号

2005-12-01 11:39 701 查看
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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: