Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Get all Machines on the Local Area network using System.DirectoryServices NameSpace .net 2.0.

Author: DevAsp Team
Download Source Code : 684_AllMachinesOnLan.zip

In this simple article you will learn how you can get all Machines on the Local Area network using System.DirectoryServices NameSpace.

Simply just create New Project of VB.

 

Firstly Add Reference of System.DirectoryServices from references.

 

Now drag one Button, one List Box, one TextBox and two Labels on the form

 

 

Now just write code on Form Load Event

 

 

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

        Me.Text = "Get All Machines"

 

        Label1.Text = "All Machines"

 

        Button1.Text = "Get All Machines"

 

        Label2.Text = "IP"

    End Sub

Now write code on Button Click Event

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        LBox.Items.Clear()

        Dim childEntry As DirectoryEntry

        Dim ParentEntry As New DirectoryEntry

        Try

            ParentEntry.Path = "WinNT:"

            For Each childEntry In ParentEntry.Children

                Select Case childEntry.SchemaClassName

                    Case "Domain"

 

                        Dim SubChildEntry As DirectoryEntry

                        Dim SubParentEntry As New DirectoryEntry

                        SubParentEntry.Path = "WinNT://" & childEntry.Name

                        For Each SubChildEntry In SubParentEntry.Children

 

                            Select Case SubChildEntry.SchemaClassName

                                Case "Computer"

                                    LBox.Items.Add(SubChildEntry.Name)

                            End Select

                        Next

                End Select

            Next

        Catch Excep As Exception

            MsgBox("Error While Reading Directories")

        Finally

            ParentEntry = Nothing

        End Try

    End Sub

 

Private Sub LBox_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LBox.SelectedValueChanged

      

 MessageBox.Show(LBox.SelectedItem().ToString())

 

    End Sub

 

After Pressing this button Your All Machine Names on Local Area Network or on your PC Load into the List Box.

Article Comments
Like the code. Can the code be enhanced to access all share points for any of the machine names in the listbox? The purpose is to access all files listed in the sharepoint assuming that the id used has authority to so.

Thanks,
Rick

Posted on 8/15/2007 1:54:56 PM by Rick Shadle

Sir,

It's fine but my request is, How can i cal the another sytem directory, if suppose 5(s1,s2,s3,s4,s5) system are in the LAN, so My application in s1. If suppose i want call s2 system directory(C,D,ELike).

Posted on 10/5/2007 3:05:17 AM by Srinivas

good

Posted on 2/16/2008 1:39:18 AM by priya

Supervev nicely done thanks

Posted on 3/31/2008 3:53:52 AM by kumaran

This code is very helpful, thanks!

Posted on 4/24/2008 4:26:49 AM by Harry

Very nice coding..Its helped me a lot...Thanks

Posted on 9/16/2008 12:20:32 AM by Sridhar R

sir,
please give me solution for checking live connected PC or H/W is connected to my PC in LAN by using IP address.

Posted on 12/2/2008 4:17:09 AM by Siddhesh

Hi,
Thanks for your valuable support. In my project, I want to collect client Pc configuration and Operating System and Memory detail and Connected Printer and Scanner detail.

Please advice me how to get these all detail?

Posted on 12/15/2008 3:46:43 PM by VEERAMANI

i get your project that's nice but dear i have one another requirement ant it is , plz give me solution how to get all the comuter name in they are in LAN and in subnet mask or workgroup etc...means get total machine not only in workgroup...plz send me solution plz

Posted on 2/3/2010 4:44:19 AM by daxesh savalia

sir, is there any method that list all the PC's connected with LAN having workgroup

Posted on 4/22/2010 3:15:54 AM by obaid

Its very nice article and its help me lots. realy thanks for given this
article

Posted on 4/24/2010 5:35:34 AM by Ilavarasam

i wanted it in c#:(

Posted on 5/25/2010 1:10:05 AM by bhargav

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How can we check that our internet connection is working or not.

Disclaimer - Privacy
© 2002-2017 DevASP.net