Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browsing Computer Names on a Network with vb.net 2

Status
Not open for further replies.

FrankiePannell

Programmer
Jul 20, 2004
6
US
I need to be able to browse for computer names on a network like in My Network Places and place them in a combo box. all I need is all the computer names not any specific file on the computer. In VB6 there was a dialog box that allowed you to do this but there does'nt seem to be one in VB.net.

Any Help Would Be Greatly Appreciated.

Thank You.
 
this should work

Code:
Imports Microsoft.VisualBasic.Compatibility
Imports System.DirectoryServices
Imports System.Collections.Specialized

...

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim PC, PcList() As String

        PcList = GetDomList("mydomainname")
        For Each PC In PcList
            ' do something
            TextBox1.Text = PC = " & PC)"
        Next
    End Sub

    Function GetDomList(ByVal domain As String) As String()
        Dim dirs, dir As DirectoryEntry
        Dim buf(-1) As String
        Dim ans As New StringCollection

        dirs = New DirectoryEntry("WinNT://" & domain)
        For Each dir In dirs.Children
            ' collect data on all of our Domain PCs
            If dir.SchemaClassName = "Computer" Then
                ans.Add(dir.Name)
            End If
        Next

        If ans.Count > 0 Then
            ReDim buf(ans.Count - 1)
            ans.CopyTo(buf, 0)
        End If
        Return buf
    End Function

End Class

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
Christiaan,

Thank you for the reply and the help.

can you think of any reason why i cant import Microsoft.VisualBasic.Compatibility
or
System.DirectoryServices

it says it cant find them.

are we running a different version of .net?
 
Thank You Christiaan for the source code I greatly appreciate it.

and

Thank You RiverGuy for the know how on the reference also greatly appreciated.
 
Just for the heck of it, one more suggestion..

I have found that the dos Net View Command might be better at telling you what computers are visible on the network right now.

What I do typicly to solve the same problem is issue a "Net View > C:\pc.txt" then open the pc.txt file (usually after giving it a few seconds to fill and start reading the pc's names by looking to see if the line starts with \\.

It seems to be very fast and will pick up pc's that aren't part of the domain. Like a visitor who has plugged into your network :)



Rob

PS a sample output file
Code:
[blue]
Server Name            Remark


-------------------------------------------------------------------------------
\\LAT600                                                                       
\\SVR039                                                                       
The command completed successfully.

[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top