Get names of computers on the same network

sarthemaker

Active member
Joined
Sep 4, 2009
Messages
36
Programming Experience
5-10
I am wondering if it is possible to retrieve the names of all shared computers on the same network as my computer, and adding them to a combo box?

Like os x leopard's finder under the shared heading on the sidebar.

(Also, if it's possible, to get a list of the shared folders on that computer?)

Thanks in advanced :)
 
This uses the active directory to list all the computers on a network.

VB.NET:
Imports System.DirectoryServices

Public Function ListNetworkComputers(ByVal strDomain As String) As ArrayList

        Dim alComputers As New ArrayList
        Dim dirSearcher As New DirectorySearcher
        Dim dsDirectoryEntry As New DirectoryEntry

        dsDirectoryEntry.Path = String.Format("LDAP://{0}", strDomain)
        dirSearcher.SearchRoot = dsDirectoryEntry
        dirSearcher.Filter = "(objectClass=computer)"

        For Each srComp As SearchResult In dirSearcher.FindAll
            alComputers.Add(srComp.Properties("name").Item(0).ToString)
        Next

        Return alComputers

End Function
 
Im not sure what the error is that your seeing. Did you add the imports statement to the top of your file. Also you may need to reference the Directory.Services.dll for it to actually see the imports statement, click "add reference" in the project menu, then on the .Net tab look for Directory.Services. As to strDomain, that is the domain name on the network that you want to search. You can use, Environment.UserDomainName to retrieve the domain name your running on.
 
This works for workgroup networks:
VB.NET:
Dim de As New DirectoryEntry
de.Path = "WinNT://workgroupname"
For Each d As DirectoryEntry In de.Children
    If d.SchemaClassName = "Computer" Then Combo.Items.Add(d.Name)
    d.Dispose()
Next
 
Back
Top