基本知识:
DirectoryEntry 组件使从目录访问对象以及使用其数据和行为非常方便。
DirectorySearcher 组件使用Active Directory架构信息在目录中执行搜索并获得节点的属性并返回 SearchResult 的实例
编程实现基本思路:
一、DirectoryEntry 类封装 Active Directory 层次结构中的节点或对象,使用此类库绑定到对象、读取属性和更新特性。DirectoryEntry 与帮助器类一起为生存期管理和导航方法提供支持,包括创建、删除、重命名、移动子节点和枚举子级。
二、使用 DirectorySearcher 类对使用轻量目录访问协议(Lightweight Directory Access Protocol,LDAP)的 Active Directory 层次结构进行搜索以查找特定的服务或对象.
用DirectoryEntry 类实例化访问对象,用DirectorySearcher 类的Filter属性过滤满足条件的信息,再用foreach遍历通过Properties可以取出OU或Users(用户)的所有属性。若需加到树结构中,使用DirectoryEntry 类的对象及Node作为参数遍历父、子级即可添加到节点中。具体付部分代码如下:
DirectoryEntry de = new DirectoryEntry("LDAP://ServerIP地址/Ou=Ou名称,CN=Users;DC=Yourdomain","administrator(管理员权限账号)","Password密码");
//Create a user account:如 创建一个用户:
DirectoryEntries users = de.Children;
DirectoryEntry newuser = users.Add("CN=" + login, "user");
// Set properties设置属性:
SetProperty(newuser,"employeeID", employeeID);
SetProperty(newuser,"givenname", name);
SetProperty(newuser,"SAMAccountName", login);
SetProperty(newuser,"userPrincipalName", login);
SetProperty(newuser,"mail", email);
newuser.CommitChanges();
http://www.cnblogs.com/downmoon/archive/2008/12/30/1365248.html
安装ADSI2.5 使用DirectoryEntry来实现