使用C#代码实现增加用户帐号

发表于:2007-06-30来源:作者:点击数: 标签:
using System; using System.DirectoryServices; //要增加此DLL文件 private void button3_Click(object sender, System.EventArgs e) { try { DirectoryEntry AD = new DirectoryEntry(WinNT:// + Environment.MachineName + ,computer); DirectoryEntry New
using System;
using System.DirectoryServices; //要增加此DLL文件


private void button3_Click(object sender, System.EventArgs e)
{
try
{
DirectoryEntry AD = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user"); //帐号
NewUser.Invoke("SetPassword", new object[] {"#12345Abc"}); // 密码
NewUser.Invoke("Put", new object[] {"Description", "Test User from .NET"});
NewUser.CommitChanges();
DirectoryEntry grp;

grp = AD.Children.Find("Guests", "group");
if (grp != null) {grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
Console.WriteLine("Aclearcase/" target="_blank" >ccount Created Successfully");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();

}
}


原文转自:http://www.ltesting.net