惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - 星星之火

Writing own regular expression parser How Regexes Work Content Based Routing Web Services in .NET and J2EE Poly-Engine Crypt String 绝不因寂寞而爱上别人 比尔·盖茨给青年一代的11点忠告 谁能简单说一下活动目录是什么东西? 广播,多播(二)(Broadcasting, Multicasting) 两毛钱爽一把 可以建立一个Udp Server,接收发往本机所有端口的数据包吗? 广播,多播(一)(Broadcasting, Multicasting) C#异步网络编程 应该由国家建立非法网站数据库 use Helper Classes to simplify you network programming a udp echo client a udp echo server xml digital signature when udp goes bad and how to solve it(C#) when tcp goes bad, and how to solve it
在.Net环境下用C#操纵活动目录 - 星星之火 - 博客园
星星之火 · 2004-07-07 · via 博客园 - 星星之火

(源出处: http://dev.csdn.net/develop/article/12/12047.shtm )


在.
Net环境下用C#操纵活动目录

王雷

Windows 2000 ServerWindows NT Server 4.0的基础上,进一步发展了"活动目录(Active Directory"。活动目录是从一个数据存储开始的。它采用了类似Exchange Server的数据存储,称为:Extensible Storage Service ESS)。其特点是不需要事先定义数据库的参数,可以做到动态地增长,性能非常优良。这个数据存储之上已建立索引的,可以方便快速地搜索和定位。活动目录的分区是"域(Domain",一个域可以存储上百万的对象。域之间还有层次关系,可以建立域树和域森林,无限地扩展。

活动目录充分体现了微软产品的"ICE",即集成性(Integration),深入性(Comprehensive),和易用性(Ease of Use)等优点。活动目录是一个完全可扩展,可伸缩的目录服务,既能满足商业ISP的需要,又能满足企业内部网和外联网的需要。

在.Net环境下操纵活动目录非常容易,其中提供了很多封装好的类用来操纵活动目录,这些类都存放在System.DirectoryServicess名称空间里。本文见简要介绍一下如何使用这些类来读取活动目录中的信息。

注:我们假设您已经对活动目录的概念有了基本的了解。

       我的网络环境由两个域控制器,和数台win2000工作站组成,安装了活动目录用来保存域里的一切信息,域名是szcs

下面我们开始建立一个简单的控制台应用程序,来读取活动目录的信息。

第一步:建立项目

(这就不多说了)

第二步:添加引用

由于操纵活动目录的类都存放在System.DirectoryServices.dll文件里。所以,我们必须在项目中添加对它的引用。

方法:在菜单中,选择 项目引用,选择System.DirectoryServices.dll确定。

第三步:引用名称空间

方法:在程序的开头出添加下面程序

using System.DirectoryServices;

第四步:编写程序

下面是一个范例程序

namespace ADsample

{

     /// <summary>

     /// Summary description for Class1.

     /// </summary>

     class Class1

     {

         static void Main(string[] args)

         {

              //

              // TODO: Add code to start application here

              //

              GetAllOU();

              Console.ReadLine();

         }

         //获取目录中需要的组织单元(OU)

         public static void GetAllOU()

         {

                   DirectoryEntry entry = new DirectoryEntry("LDAP://szcs");

                   DirectorySearcher mySearcher = new DirectorySearcher(entry);

                   mySearcher.Filter = ("(objectClass=organizationalUnit)");

                   foreach(SearchResult resEnt in mySearcher.FindAll())

                   {

                        Console.Write(resEnt.GetDirectoryEntry().Name.ToString());

   Console.WriteLine("\t"resEnt.GetDirectoryEntry().Name.ToString());

                   }//end foreach

         }//end GetAllOU

     }//end class

}//end namespace

程序注解:

ü         程序开始,实例化了一个DirectoryEntry类,其构造函数的参数是"LDAP://szcs",这里szcs是域名。

ü         然后又实例化了一个DirectorySearcher类,用来查询szcs域中活动目录中的信息,其构造函数的参数是一个DirectoryEntry类的实例对象。

ü         DirectorySearcher类的Filter属性用来设置查询的过滤条件,一般有以下三种:

1.       objectClass=organizationalUnit    查询条件是所有的组织单元(OU)

2.       objectClass=group                 查询条件是所有的组(GROUP)

3.       objectClass=user                  查询条件是所有的用户(USER)

当然还可以设置其他的过滤条件,而且可以使用逻辑运算符,详情请参加MSDN

ü   DirectorySearcher类的Findall方法用来递归的查找所有符合条件的对象。其返回结果

是一个SearchResult类型的对象,这是一个集合类型。

ü   Foreach语句访问集合中的所有对象,获得对象的信息。