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("account created successfully");
console.readline();
}
catch (exception ex)
{
console.writeline(ex.message);
console.readline();
}
}