Class1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.DirectoryServices;
  3. namespace Wrox.ProCSharp.ActiveDirectory
  4. {
  5. /// <summary>
  6. /// Summary description for Class1.
  7. /// </summary>
  8. class Class1
  9. {
  10. /// <summary>
  11. /// The main entry point for the application.
  12. /// </summary>
  13. [STAThread]
  14. static void Main(string[] args)
  15. {
  16. using (DirectoryEntry de = 
  17.    new DirectoryEntry("LDAP://OU=Wrox Press, DC=athenaproject, DC=local"))
  18. using (DirectorySearcher searcher = new DirectorySearcher())
  19. {     
  20. searcher.SearchRoot = de;
  21. searcher.Filter = "(&(objectClass=user)(description=Auth*))";
  22. searcher.SearchScope = SearchScope.Subtree;
  23. searcher.PropertiesToLoad.Add("name");
  24. searcher.PropertiesToLoad.Add("description");
  25. searcher.PropertiesToLoad.Add("givenName");
  26. searcher.PropertiesToLoad.Add("wWWHomePage");
  27. searcher.Sort = new SortOption("givenName", SortDirection.Ascending);
  28. SearchResultCollection results = searcher.FindAll();
  29. foreach (SearchResult result in results)
  30. {
  31. ResultPropertyCollection props = result.Properties;
  32. foreach (string propName in props.PropertyNames)
  33. {
  34. Console.Write(propName + ": ");
  35. Console.WriteLine(props[propName][0]); 
  36. }
  37. Console.WriteLine();
  38. }
  39. }
  40. }
  41. }
  42. }