예제 #1
0
        private List<ADDomain> GetNetBIOSDomains()
        {
            List<ADDomain> ret = new List<ADDomain>();
            DirectoryEntry RootDSE = new DirectoryEntry("LDAP://rootDSE");

            // Retrieve the Configuration Naming Context from RootDSE
            string configNC = RootDSE.Properties["configurationNamingContext"].Value.ToString();

            // Connect to the Configuration Naming Context
            DirectoryEntry configSearchRoot = new DirectoryEntry("LDAP://" + configNC);

            // Search for all partitions where the NetBIOSName is set.
            DirectorySearcher configSearch = new DirectorySearcher(configSearchRoot);
            configSearch.Filter = ("(NETBIOSName=*)");

            // Configure search to return dnsroot and ncname attributes
            configSearch.PropertiesToLoad.Add("dnsroot");
            configSearch.PropertiesToLoad.Add("NETBIOSName");
            SearchResultCollection forestPartitionList = configSearch.FindAll();

            // Loop through each returned domain in the result collection
            foreach (SearchResult domainPartition in forestPartitionList)
            {
                ADDomain ad = new ADDomain();
                ad.Name = domainPartition.Properties["NETBIOSName"][0].ToString();
                ad.Path = domainPartition.Properties["NETBIOSName"][0].ToString();
                ret.Add(ad);
            }
            return ret;
        }