感谢您使用微软产品。在.Net环境下操纵活动目录非常容易,其中提供了很多封装好的类用来操纵活动目录,这些类都存放在System.DirectoryServicess名称空间里。通过DirectorySearcher类的Filter属性用来设置查询的过滤条件,如下面mySearcher.Filter = ("(objectClass=user)");用来设定查询条件是所有的用户。
下面,提供一个简单的示例程序,供您参考:
1,实例化一个DirectoryEntry类,其构造函数的参数是"LDAP:// _YOURDOMAINNAME_",这里_YOURDOMAINNAME_是域名;
2,实例化了一个DirectorySearcher类mySearcher,用来查询_YOURDOMAINNAME_域中活动目录中的信息,其构造函数的参数是一个DirectoryEntry类的实例对象entry。
using System;
using System.DirectoryServices;   namespace ActiveDirectory

class Class1
{
    static void Main (string[] args)
    {
        DirectoryEntry entry = new DirectoryEntry("LDAP://_YOURDOMAINNAME_");
        System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
        mySearcher.Filter = ("(objectClass=user)");
        Console.WriteLine("Active Directory Information");  
        Console.WriteLine("==========================");           foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
       {
         Console.WriteLine("名称 = " +  resEnt.GetDirectoryEntry().Name.ToString() );
         Console.WriteLine("路径 = " +  resEnt.GetDirectoryEntry().Path.ToString() );
         Console.WriteLine("=================");          
     }
     }
}
}  关于DirectoryServices的更详细信息及其示例程序,请参考微软官方网站:
http://msdn.microsoft.com/library/default.asp?PP=/library/toc/cpref/cpref0-25.xml&tocPath=cpref0-25&URL=/library/dotnet/cpref/frlrfSystemDirectoryServices.htm
 — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。