zoukankan      html  css  js  c++  java
  • AD学习--如何获得域中的用户

    代码出自http://www.c-sharpcorner.com//Code/2003/April/ListingADUsers.asp

    Console.Write("Enter your Domain Name : ");
       string dom =Console.ReadLine();

       System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + dom);
       System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
       mySearcher.Filter = ("(objectClass=user)");//filte the objectClass type

    //    mySearcher.Filter = ("(&(objectCategory=person)(objectClass=user)(sAMAccountName=xxx))");//filte
    the objectClass type
       Console.WriteLine("Listing of users in the Active Directory"); 
       Console.WriteLine("========================================");   
     

       foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
       {
        try
        {
         System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
         Console.WriteLine("Display Name  : " + de.Properties["DisplayName"].Value.ToString());
         Console.WriteLine("Email         : " + de.Properties["Mail"].Value.ToString()); 
         Console.WriteLine("Title         : " + de.Properties["Title"].Value.ToString());   
         Console.WriteLine("User Name     : " + de.Properties["sAMAccountName"].Value.ToString());
         Console.WriteLine("First Name    : " + de.Properties["GivenName"].Value.ToString());     
         Console.WriteLine("Last Name     : " + de.Properties["sn"].Value.ToString()); 
         Console.WriteLine("Initials      : " + de.Properties["Initials"].Value.ToString()); 
         Console.WriteLine("Company       : " + de.Properties["Company"].Value.ToString());
         Console.WriteLine("Department    : " + de.Properties["Department"].Value.ToString());
         Console.WriteLine("Telephone No. : " + de.Properties["TelephoneNumber"].Value.ToString()); 
        }
        catch(Exception e)
        {
        }
        Console.WriteLine("===========    End of user   =============");                                  
        
       }
       Console.WriteLine("===========    End of Listing   =============");

    From <http://msdn.microsoft.com/en-us/library/windows/desktop/aa746475(v=vs.85).aspx>

    Search filterDescription
    "(objectClass=*)" All objects.
    "(&(objectCategory=person)(objectClass=user)(!cn=andy))" All user objects but "andy".
    "(sn=sm*)" All objects with a surname that starts with "sm".
    "(&(objectCategory=person)(objectClass=contact)(|(sn=Smith)(sn=Johnson)))" All contacts with a surname equal to "Smith" or "Johnson".
  • 相关阅读:
    bzoj 1927: [Sdoi2010]星际竞速
    bzoj 1926: [Sdoi2010]粟粟的书架
    bzoj 1923: [Sdoi2010]外星千足虫
    bzoj 1922: [Sdoi2010]大陆争霸
    bzoj 1911: [Apio2010]特别行动队
    bzoj 1878: [SDOI2009]HH的项链
    bzoj 1877: [SDOI2009]晨跑
    bzoj 1856: [Scoi2010]字符串
    bzoj 1854: [Scoi2010]游戏
    python小练习,打出1-100之间的所有偶数,设计一个函数,在桌面上创建10个文件,并以数字命名,复利计算函数
  • 原文地址:https://www.cnblogs.com/stswordman/p/396130.html
Copyright © 2011-2022 走看看