c#进行AD添加用户
2010-02-17 17:23
281 查看
DirectoryEntry objDE;
//列出用户
objDE=new DirectoryEntry("LDAP://yourserver/cn=users,dc=xxx,dc=com","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
foreach(DirectoryEntry ch in objDE.Children)
Response.Write(ch.Path+""+ch.SchemaClassName+"");
//建用户
DirectoryEntry objDE1=objDE.Children.Add("cn=newtest","user");
objDE1.Invoke("Put",new Object[2] {"givenName","newtest"});
objDE1.Invoke("Put",new Object[2] {"samAccountName","newtest"});
objDE1.Invoke("Put",new Object[2] {"userPrincipalName","newtest"});
objDE1.Invoke("Put",new Object[2] {"UserAccountControl","512"});
objDE1.CommitChanges();
objDE1.Invoke("ChangePassword",new Object[2] {"","pwd"});
objDE1.CommitChanges();
如果要查找所有容器下的user,用DirectorySearcher
DirectoryEntry objDE=new DirectoryEntry("LDAP://yourserver","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(objDE);
mySearcher.Filter = ("(objectClass=user)");
foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
Response.Write( resEnt.Path+"--------------------------------------------------------------------------------");
}
//列出用户
objDE=new DirectoryEntry("LDAP://yourserver/cn=users,dc=xxx,dc=com","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
foreach(DirectoryEntry ch in objDE.Children)
Response.Write(ch.Path+""+ch.SchemaClassName+"");
//建用户
DirectoryEntry objDE1=objDE.Children.Add("cn=newtest","user");
objDE1.Invoke("Put",new Object[2] {"givenName","newtest"});
objDE1.Invoke("Put",new Object[2] {"samAccountName","newtest"});
objDE1.Invoke("Put",new Object[2] {"userPrincipalName","newtest"});
objDE1.Invoke("Put",new Object[2] {"UserAccountControl","512"});
objDE1.CommitChanges();
objDE1.Invoke("ChangePassword",new Object[2] {"","pwd"});
objDE1.CommitChanges();
如果要查找所有容器下的user,用DirectorySearcher
DirectoryEntry objDE=new DirectoryEntry("LDAP://yourserver","Administrator","pwd",System.DirectoryServices.AuthenticationTypes.ServerBind);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(objDE);
mySearcher.Filter = ("(objectClass=user)");
foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
Response.Write( resEnt.Path+"--------------------------------------------------------------------------------");
}
相关文章推荐
- 在asp.net中,我用c#进行AD操作,添加用户
- ad目录中添加用户属性
- 通过WEB方式添加AD用户的问题
- 在WIN2K3AD中用dsadd批量添加域用户
- 在AD中批量添加多个用户帐号
- 进行添加评论操作,添加时,先查询用户是否登录
- AD不能把用户添加到组排错经过(w32.spybot.worm的疑问?)
- Netscreen防火墙使用AD进行用户验证
- 在app未开启时,实现对用户进行通知提醒功能总结(添加事件到手机系统日历并设置闹钟提醒)
- 获取AD域中的组织单位域用户,并且对用户大于1000个的进行分批读取
- 在AD中批量添加多个用户帐号
- AD添加用户时,提示“目录服务已经用完相对标识符池”
- AD中如何让普通域用户帐号能拥有不受次数限制添加计算机到域的权限?
- Java添加、修改MS AD用户密码
- 用Tsung对XMPP进行压力测试,登陆用户只有十几个,无法再添加,何故?
- 如何将本地AD域用户和Office 365用户进行强制同步
- 利用CSVDE批量添加AD用户
- 【C#代码】使用C#为AD添加用户