asp.net操作活动目录
最近在写一个关于asp.net 操作AD的程序,卡住了,快一个星期了一点点进展都没有,从网上也找了不资料但都不能用,该报什么错还是报什么错.。先把对的贴出来,希望对大家有所帮助
添加用户名
try
{
DirectoryEntry entry = new DirectoryEntry(path, "Administrator", " ", AuthenticationTypes.Secure);
//DirectoryEntry subEntry = entry.Children.Find("ou=jypx", "organizationalUnit");
DirectoryEntry deUser = entry.Children.Add("cn=" + sAMAccountName.Text, "user");
deUser.Properties["Sn"].Value = Sn.Text;//姓
deUser.Properties["GivenName"].Value = GivenName.Text;//名
deUser.Properties["Department"].Value = Department.Text;////部门
deUser.Properties["Title"].Value = Title.Text;//职位
deUser.Properties["telephoneNumber"].Value = mobile.Text;//电话
deUser.Properties["Mail"].Value = Email.Text;//email
deUser.Properties["userPrincipalName"].Value = sAMAccountName.Text;//登录名
deUser.Properties["sAMAccountName"].Value = sAMAccountName.Text;
deUser.Properties["useraccountcontrol"].Value = 544;//544开启,514关闭
deUser.CommitChanges();
deUser.Close();
Response.Write("<script>alert('添加用户成功')</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('添加用户失败,可能该用户已经存在')</script>");
}
这些代码都没有错,但如果添加用户时添加密码就会出错,我看了网上基本上是两种方法一种是
在添加其它属性的同时添加
deUser.Invoke("SetPassWord", new object[] { "ABcd123" });
或是在提交之后用
deUser.Invoke("ChangePassword", new object[] { "ABcd123" });
两个都试过了,不行,不知道是哪里的原因!![]()
还有就是不知道怎么更改用户CN的组织单位,有个MOVETO方法不知道是不是更改的,试了试也没成功!

浙公网安备 33010602011771号