Solved

How to get windows domain list in a combo box (asp.net)

Posted on 2004-09-07
6
463 Views
Last Modified: 2008-03-17
Hi All,

Does any one know how to get the list of all available windows domains (domain list) into a combo box? Similar to the combo box that we get while logging into windows.

Thanks
Konda
0
Comment
Question by:madhukar_konda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:madhukar_konda
ID: 11995257
Previously I got the following answer from TheLearnedOne.

Public Function EnumerateDomains() As ArrayList

    Dim arrayDomains As New ArrayList

    Try

      Dim queryString As String = "Select domain From Win32_ComputerSystem"

      Dim searchDomains As New Management.ManagementObjectSearcher(queryString)

      For Each domainCurrent As Management.ManagementBaseObject In searchDomains.Get
        arrayDomains.Add(domainCurrent.Properties("Domain").Value)
      Next domainCurrent

    Catch ex As Exception
      MessageBox.Show(ex.ToString)
    End Try

    Return arrayDomains

  End Function 'EnumerateDomains'

But, this function is returning currently user logged in domain. I want all the existing domains. Any ideas??
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 11995571
Hello

   Try this code

private void button1_Click(object sender, System.EventArgs e)
            {
                  StringCollection adDomains = this.GetDomainList();
                  foreach (string strDomain in adDomains)
                  {
                        comboBox1.Items.Add(strDomain);
                  }
            }



            private StringCollection GetDomainList()
            {
                  StringCollection domainList = new StringCollection();
                  try
                  {
                        DirectoryEntry en = new DirectoryEntry("LDAP://");
                        // Search for objectCategory type "Domain"
                        DirectorySearcher srch = new DirectorySearcher("objectCategory=Domain");
                        SearchResultCollection coll = srch.FindAll();
                        // Enumerate over each returned domain.
                        foreach (SearchResult rs in coll)
                        {
                              ResultPropertyCollection resultPropColl = rs.Properties;
                              foreach( object domainName in resultPropColl["name"])
                              {
                                    domainList.Add(domainName.ToString());
                              }
                        }
                  }
                  catch (Exception ex)
                  {
                        MessageBox.Show (ex.Message);
                  }
                  return domainList;
            }

HTH

Regards,
Mohammed
0
 

Author Comment

by:madhukar_konda
ID: 11995719
Hi Mohammed.

Thanks for your reply. But it is giving me only one domain to which i logged in. any ideas?

I want all the available domains in the network. Similar to windows login screen domain list.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 500 total points
ID: 12004681
Hello  madhukar_konda

  Here's a simplier way, and it should return all the domain in your network

public ArrayList GetDomains()
{
      DirectoryEntry dn = new DirectoryEntry("WinNT:");
      ArrayList Domains = new ArrayList();
      try                  
      {
            foreach (DirectoryEntry chd in dn.Children)
            {
                  Domains.Add(chd.Name);                              
            }
      }
      catch (Exception ex)
      {
            MessageBox.Show(ex.Message);
      }                  
      return Domains;
}

private void button2_Click(object sender, System.EventArgs e)
{
      foreach (string s in GetDomains())
      comboBox1.Items.Add(s);
}

Regards,
Mohammed
0
 

Author Comment

by:madhukar_konda
ID: 12013410
Thanks Mohammed!

It does work. I really appriciate your quick response.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12013421
Glad to help you :-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question