在asp.net中,我用c#进行AD操作,添加用户

来源:互联网 发布:黄金现货行情软件 编辑:程序博客网 时间:2024/06/10 05:50
主  题:
关于 AD ,高手请进,在线等待
在asp.net中,我用c#进行AD操作,添加用户,我怎么才能列举本域中下面的所有用户,包括Users,和自己建立的组织单位,请举例,谢谢
回复人: yxrj() ( ) 信誉:105 2002-07-23 09:38:35Z 得分:50 ?
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();
Top回复人: yxrj() ( ) 信誉:105 2002-07-23 10:15:29Z 得分:50 ?
如果要查找所有容器下的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+"
"); }
Top回复人: yxrj() ( ) 信誉:105 2002-07-23 10:22:49Z 得分:0 ?
如果要查找所有容器下的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+"
");}
Top回复人: Richard2001(Richard) ( ) 信誉:98 2002-07-23 10:30:27Z 得分:0 ?
我也试试。
Top回复人: cuiaimin(Shadow) ( ) 信誉:99 2002-07-23 10:54:37Z 得分:0 ?
谢谢yxrj
Top回复人: ameng_2002(flyfox) ( ) 信誉:105 2002-07-23 11:09:33Z 得分:0 ?
gz
Top回复人: ketao_78(树欲静而风不止) ( ) 信誉:101 2002-07-23 14:20:45Z 得分:0 ?
哇,这个可真够厉害