using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//using System.DirectoryServices;
using System.Diagnostics;

using System.IO;

namespace CreateUser


{

/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form

{
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox txtPath;
private System.Windows.Forms.Label label1;

/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()

{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.txtPath.Text =Application.StartupPath+@"\User.txt";
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}


/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )

{
if( disposing )

{
if (components != null)

{
components.Dispose();
}
}
base.Dispose( disposing );
}


Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

{
this.button2 = new System.Windows.Forms.Button();
this.txtPath = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button2
//
this.button2.Location = new System.Drawing.Point(80, 40);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "批量创建";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// txtPath
//
this.txtPath.Location = new System.Drawing.Point(80, 8);
this.txtPath.Name = "txtPath";
this.txtPath.Size = new System.Drawing.Size(256, 20);
this.txtPath.TabIndex = 3;
this.txtPath.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 4;
this.label1.Text = "文件路径:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 77);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtPath);
this.Controls.Add(this.button2);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "批量创建用户";
this.ResumeLayout(false);

}
#endregion


/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()

{
Application.Run(new Form1());
}

/**//* private void AddUser( string strLogin, string strPwd)
{ strDoamin=".";
DirectoryEntry obDirEntry = null;
obDirEntry = new DirectoryEntry("WinNT://" + strDoamin);
DirectoryEntries entries = obDirEntry.Children;
DirectoryEntry obUser = entries.Add(strLogin, "User");
obUser.Properties["FullName"].Add("sifang");
obUser.Properties["Description"].Add("sifang");
obUser.Properties["Usercannotchangepassword"].Add(true);
obUser.Properties["Passwordneverexpires"].Add(true);
object obRet = obUser.Invoke("SetPassword", strPwd);
obUser.CommitChanges();
}
*/


private void button2_Click(object sender, System.EventArgs e)

{
readfile();
}

public void CreateUser(string stru,string strp)

{
Process msgProcess = new Process();
msgProcess.StartInfo.FileName = @"net.exe";
msgProcess.StartInfo.CreateNoWindow = true;
string cmd1="user "+stru+" "+strp+ " /add";
//string cmd2="user "+stru+" /delete";
msgProcess.StartInfo.Arguments = cmd1;
//msgProcess.StartInfo.Arguments = cmd2;
msgProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
msgProcess.StartInfo.UseShellExecute = false;
msgProcess.StartInfo.RedirectStandardOutput = true;
msgProcess.Start();
msgProcess.WaitForExit();
}

private void readfile()

{
if(!File.Exists(this.txtPath.Text))

{
MessageBox.Show("请输入文件路径或者文件路径不存在","错误信息");
}
else

{
StreamReader objReader = new StreamReader(this.txtPath.Text);
string sLine="";
ArrayList arrText = new ArrayList();

while (sLine != null)

{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();

foreach (string sOutput in arrText)

{
string[] strArr=sOutput.Split(',');
//for(int i=0;i<strArr.Length;i++)
//{
CreateUser(strArr[0],strArr[0]);
//}

}
MessageBox.Show("共创建"+arrText.Count.ToString()+"用户!");
}

}

}
}

批量创建windows用户这里用两种方法
一种ADSI using System.DirectoryServices;
另一种调用net.exe来构造命令来执行。
在使用ADSI时有些属性无法查到。使用Net.exe更灵活一些。
代码下载
https://files.cnblogs.com/Hover/CreateUser.rar