?
Solved

Detecing Network

Posted on 2007-07-27
8
Medium Priority
?
169 Views
Last Modified: 2013-11-26
Hi, By using VB.Net i want to detect the computers' names which are connected to network, Can I ?
Thanx
0
Comment
Question by:ashraf_t
  • 3
5 Comments
 
LVL 6

Expert Comment

by:ToFro
ID: 19581275
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

0
 
LVL 6

Expert Comment

by:ToFro
ID: 19581312
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"
0
 

Author Comment

by:ashraf_t
ID: 19581732
there is no active directory , it just a simple netwrok
0
 
LVL 6

Accepted Solution

by:
ToFro earned 100 total points
ID: 19581987
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 total points
ID: 19582011
You could use the net view /domain way:

Imports System.Collections.Generic
Imports System.Diagnostics

Public Class NetViewDomain

  Public Shared Function GetDomainList(ByVal domain As String) As Dictionary(Of String, String)

    Dim proc As New Process()

    proc.StartInfo.FileName = "net.exe"
    proc.StartInfo.Arguments = "view /domain:" & domain
    proc.StartInfo.RedirectStandardOutput = True
    proc.StartInfo.UseShellExecute = False
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    proc.Start()

    proc.WaitForExit(20000)

    Dim output As String = proc.StandardOutput.ReadToEnd()

    Return ParseNames(output)

  End Function

  Private Shared Function ParseNames(ByVal input As String) As Dictionary(Of String, String)

    Dim list As New Dictionary(Of String, String)

    Dim text As New TextBox()
    Dim withinBlock As Boolean
    text.WordWrap = False
    text.Text = input

    For Each line As String In text.Lines
      If withinBlock Then
        Dim position As Integer = line.IndexOf(" ")
        If position <> -1 AndAlso Not line.Equals("The command completed successfully.") Then
          Dim name As String = line.Substring(0, position).Trim()
          Dim value As String = line.Substring(position + 1).Trim()
          list.Add(name, value)
        End If
      Else
        withinBlock = line.StartsWith("Server Name")
      End If
    Next line

    Return list

  End Function

End Class

Sample:
Dim computers As Dictionary(Of String, String) = NetViewDomain.GetDomainList(Environment.UserDomainName)

Bob

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question