感谢您使用微软产品。在.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))。
下面,提供一个简单的示例程序,供您参考:
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))。
解决方案 »
- 跨线程事件问题
- 【送全分】请教Dev带图片的报表导出Excel后中无法复制粘贴的问题
- 如何格式化这个字符串时间啊
- 有没有哪位大侠做过名片扫描的程序?急呀
- 如何删除数组中的重复数据阿?
- 关于SqlDataAdapter.fill一个比较难的问题
- 关于config文件的读取
- C# 怎么把画在picture控件图形保存为PDF格式的文件
- DevExpress中grid里单元格赋值的问题
- 求类似Excel的 .net 网格控件
- 高分求救: 安装visaul Studio 7 时候让我更新windows组件,但是我找不到
- 问问各位大虾:::C#正式版刚出来,它跟以前的测试版有多大差别??现在市面上的有关c#的书肯定都是以测试版为标准的,是不是应该等一段
而在Web Form 和 Web Service 中查出的结果为0条记录呢???