Hi getasew,
Refer the below code to get all the computer connected in the Lan Network. For this you need add reference of System.DirectoryService dll in your reference folder.
C#
protected void Page_Load(object sender, EventArgs e)
{
string a = "";
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry computers in root.Children)
{
foreach (DirectoryEntry computer in computers.Children)
{
if (computer.Name != "Schema" && computer.SchemaClassName == "Computer")
{
a += "<b>Path: </b>" + computer.Path + "<b> Name: </b>" + computer.Name + "<br/>";
}
}
}
Response.Write(a);
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim a As String = ""
Dim root As New DirectoryEntry("WinNT:")
For Each computers As DirectoryEntry In root.Children
For Each computer As DirectoryEntry In computers.Children
If computer.Name <> "Schema" AndAlso computer.SchemaClassName = "Computer" Then
a += "<b>Path: </b>" + computer.Path + "<b> Name: </b>" + computer.Name + "<br/>"
End If
Next
Next
Response.Write(a)
End Sub
Namespace
C#
using System.DirectoryServices;
VB.Net
Imports System.DirectoryServices
Output
Path: WinNT://EXCELASOFT/EXCELASOFT22 Name: EXCELASOFT22
Path: WinNT://EXCELASOFT/EXCELASOFT25 Name: EXCELASOFT25
Path: WinNT://EXCELASOFT/EXCELASOFT29 Name: EXCELASOFT29
Path: WinNT://EXCELASOFT/EXCELASOFT30 Name: EXCELASOFT30
Path: WinNT://EXCELASOFT/EXCELASOFT46 Name: EXCELASOFT46
Path: WinNT://EXCELASOFT/EXCELASOFT56 Name: EXCELASOFT56