?
Solved

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

Posted on 2004-09-07
6
Medium Priority
?
464 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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