Class1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
- using System;
- using System.DirectoryServices;
- namespace Wrox.ProCSharp.ActiveDirectory
- {
- /// <summary>
- /// Summary description for Class1.
- /// </summary>
- class Class1
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main(string[] args)
- {
- using (DirectoryEntry de =
- new DirectoryEntry("LDAP://OU=Wrox Press, DC=athenaproject, DC=local"))
- using (DirectorySearcher searcher = new DirectorySearcher())
- {
- searcher.SearchRoot = de;
- searcher.Filter = "(&(objectClass=user)(description=Auth*))";
- searcher.SearchScope = SearchScope.Subtree;
- searcher.PropertiesToLoad.Add("name");
- searcher.PropertiesToLoad.Add("description");
- searcher.PropertiesToLoad.Add("givenName");
- searcher.PropertiesToLoad.Add("wWWHomePage");
- searcher.Sort = new SortOption("givenName", SortDirection.Ascending);
- SearchResultCollection results = searcher.FindAll();
- foreach (SearchResult result in results)
- {
- ResultPropertyCollection props = result.Properties;
- foreach (string propName in props.PropertyNames)
- {
- Console.Write(propName + ": ");
- Console.WriteLine(props[propName][0]);
- }
- Console.WriteLine();
- }
- }
- }
- }
- }