Display names of computers on a network in a combo box

I know that this must be posted somewhere, but I can't find it. Hopefully this won't make you mad as this has probably been asked many times:

I need to display the names of computers within a network in a combo Box.

I have recently restarted to do a bit of programming and I have forgotten nearly everything, so please excuse me if I don't know what you mean.


Answer this question

Display names of computers on a network in a combo box

  • Tibor den Ouden

    Thanks for that I am going to try it now, once my computer has cooled down. It appeares to be overheating again. I did a major HD Defragment that took over 2 hours. I am wondering, would my PC overheating cause my internet connection to freeze resulting me in having to manually reset the connection

    It am told that domain is not declared in this line, spotty:

    Dim enTry As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry("LDAP://" & Domain)

    The code is allright in this part of the code:
    Private Sub GetNetCom(ByRef Combobox1 As ComboBox, ByVal Domain As String)

    but not in:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged



  • Tim Daniels

    I am now recieving COMException was unhandled. The server is not operational. What server would this be refering to

     


  • HoustonRocket

    Last post of this thread http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=215715&SiteID=1 has the code.

    Add a reference to System.DirectoryServices to your project and imports System.DirectoryServices in your code file.


  • Tom D

    You need to provide the function with the combobox you want to populate and the domain for your network.

    Private Sub GetNetCom(Byref Combobox1 as combobox, Byval Domain as string)
    Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://" & Domain )
    Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
    mySearcher.Filter = ("(objectClass=computer)")

    Dim resEnt As SearchResult
    Dim strPCs As String
    ComboBox1.Items.Clear
    For Each resEnt In mySearcher.FindAll()
    'Get rid of those CN= prefixes
    strPCs = Replace(resEnt.GetDirectoryEntry().Name.ToString(), "CN=", "")
    'Add those to treeview
    ComboBox1.Items.Add(strPCs)
    Next
    End Sub


  • Elkoda

    It wont be OK in the 2nd one as when you would change the combobox1 it would clear the items in combobox1 thereby causing a another selectedIndex change because the currently selected item would now not exist in the combobox1.

    The reason I had put it in a separate function was that you could call it to populate any combobox. Combobox1 just happens to be a parameter I used on the method.

    When do you want to populate the combobox When the form loads - when a button is clicked, when another combobox or list is selected.

    Dim enTry As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry("LDAP://" & Domain)

    Domain was a parameter that was being passed into the method I had provided but if you have put this directly in you combobox select routine you'll have to provide it yourself. Again the reason why a method was provided was that the same routine could be used for different network domains rather than having hardcoded values in your code.


  • Keldon Alleyne

    I have done so but the list of computers on a network do not appear in the Combo Box.


  • Andy!

    This tip on the vb-tips website shows how to use the directory services classes to load a list of computers into a combobox.  If you are not using a network that has active directory try this tip instead.

  • Display names of computers on a network in a combo box