Link to home
Start Free TrialLog in
Avatar of ashraf_t
ashraf_t

asked on

Detecing Network

Hi, By using VB.Net i want to detect the computers' names which are connected to network, Can I ?
Thanx
Avatar of ToFro
ToFro
Flag of Finland image

If you have an Active Directory in your network, you can retrieve machines with the System.DirectoryServices namespace, Just add a reference System.DirectoryServices.dll, then add the following code to the Form Load Event(you need a multiline TextBox TextBox1 on your Form):

//... Add this to the top of your code:
Imports System.DirectoryServices

//...Add this inside the Form Load EventHandler:

        Dim objDirEnt As DirectoryEntry = New DirectoryEntry(adpath,username,password)
        Dim objChildDE As DirectoryEntry
        For Each objChildDE In objDirEnt.Children
            TextBox1.Text += objChildDE.Name + vbNewLine
        Next objChildDE

The adpath you'll have to figure out for yourself. Try something like this(replace DOMAINNAME):
Dim adpath As String = "LDAP://DOMAINNAME.LOCAL/CN=Computers,DC=DOMAINNAME,DC=LOCAL"

... You can swap "CN=Computers" for "CN=Users" to get all the users.

For username and password, the credentials of a user with administrator rights to the server should be enough.

Dim username As String = "UserWithServerAdministratorPrivileges"
Dim password As String = "UsersPassword"
Avatar of ashraf_t
ashraf_t

ASKER

there is no active directory , it just a simple netwrok
ASKER CERTIFIED SOLUTION
Avatar of ToFro
ToFro
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial