首页 > 开发 > 综合 > 正文

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

2024-07-21 02:18:11
字体:
来源:转载
供稿:网友

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();

}
}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表