Retrive the List Of Computers in Network

Initiotech
Posted by Initiotech under VB.NET category on | Views : 3017
This code sample is used to get all the names of computers that are there in your network.
You need to Iterate with the Children entries of the Directory Entries.

The Below Sample is in Console Application

Sub Main()
Dim root As New DirectoryEntry("WinNT:")
Dim parent As DirectoryServices.DirectoryEntries
parent = root.Children
Dim d As DirectoryEntries = parent
For Each complist As DirectoryEntry In parent
For Each c As DirectoryEntry In complist.Children
If (c.Name <> "Schema") Then
Console.WriteLine(c.Name)
End If
Next
Next
End Sub

You can use the same code to Add the Names of the Network Computers in a Combobox or a ListBox
            
For Each c As DirectoryEntry In complist.Children
If (c.Name <> "Schema") Then
ComboBox1.Items.Add(c.Name)
End If
Next


Regards
Hefin Dsouza

Comments or Responses

Posted by: Naimishforu on: 7/25/2011 Level:Bronze | Status: [Member] [MVP] | Points: 10
Just a little note that, you will have to Import System.DirectoryServices :)


Login to post response