Results 1 to 19 of 19

Thread: Listing Network Computers

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Listing Network Computers

    Hi guys!
    I'm looking for a code that lists all computers in the LAN.
    Is it possible? Is it difficult?

    I'm doing the first steps in VB.

    I'm using VB Studio .Net 2003.
    Help me. Thanks on advance

    Sorry about the English but I'm a portuguese teenager.
    And sorry for the ignorance!

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    Check this thread out. It looks like they did it.

    Another
    http://www.vbforums.com/showthread.p...ht=wmi+network
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    I'm sorry, but I can't do it.
    Can anyone make a form for me please.

    Sorry! I'd thank you!

  4. #4
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    I highly doubt that anyone is going to make your project for you. But if you post what you have and let us know what the problem is we will be more than happy to help you work it out.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    OK! Thanx for your reply!
    I'll try to explain what I'm trying to do!

    All I want is to make an application that sends a message to a computer in the LAN with 'net send' command.
    I've already done this, but I first have to know the name or the IP of the computer I want to send the message to.

    I'd like to have a listbox with all computers in the LAN (and if possible) their IPs.

  6. #6
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    So as I said what code do you have and what is the issue you're having? I know one of the links I posted has an example app attached. May not be exactly what you need but it should give you a starting point.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    I've tried a 'class' file that's attached to a post. But i culdn't work witha that. Many errors.

    The code that I have is very very simple:
    VB Code:
    1. Public Class Form2
    2.     Inherits System.Windows.Forms.Form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.     Public Sub New()
    7.         MyBase.New()
    8.  
    9.         'This call is required by the Windows Form Designer.
    10.         InitializeComponent()
    11.  
    12.         'Add any initialization after the InitializeComponent() call
    13.  
    14.     End Sub
    15.  
    16.     'Form overrides dispose to clean up the component list.
    17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    18.         If disposing Then
    19.             If Not (components Is Nothing) Then
    20.                 components.Dispose()
    21.             End If
    22.         End If
    23.         MyBase.Dispose(disposing)
    24.     End Sub
    25.  
    26.     'Required by the Windows Form Designer
    27.     Private components As System.ComponentModel.IContainer
    28.  
    29.     'NOTE: The following procedure is required by the Windows Form Designer
    30.     'It can be modified using the Windows Form Designer.  
    31.     'Do not modify it using the code editor.
    32.     Friend WithEvents Label2 As System.Windows.Forms.Label
    33.     Friend WithEvents Label1 As System.Windows.Forms.Label
    34.     Friend WithEvents msg_net As System.Windows.Forms.TextBox
    35.     Friend WithEvents ip As System.Windows.Forms.TextBox
    36.     Friend WithEvents btn_env As System.Windows.Forms.Button
    37.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    38.         Me.Label2 = New System.Windows.Forms.Label
    39.         Me.Label1 = New System.Windows.Forms.Label
    40.         Me.btn_env = New System.Windows.Forms.Button
    41.         Me.msg_net = New System.Windows.Forms.TextBox
    42.         Me.ip = New System.Windows.Forms.TextBox
    43.         Me.SuspendLayout()
    44.         '
    45.         'Label2
    46.         '
    47.         Me.Label2.BackColor = System.Drawing.Color.Transparent
    48.         Me.Label2.ForeColor = System.Drawing.Color.Black
    49.         Me.Label2.Location = New System.Drawing.Point(8, 32)
    50.         Me.Label2.Name = "Label2"
    51.         Me.Label2.Size = New System.Drawing.Size(64, 16)
    52.         Me.Label2.TabIndex = 35
    53.         Me.Label2.Text = "Mensagem:"
    54.         Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
    55.         '
    56.         'Label1
    57.         '
    58.         Me.Label1.BackColor = System.Drawing.Color.Transparent
    59.         Me.Label1.ForeColor = System.Drawing.Color.Black
    60.         Me.Label1.Location = New System.Drawing.Point(8, 8)
    61.         Me.Label1.Name = "Label1"
    62.         Me.Label1.Size = New System.Drawing.Size(64, 16)
    63.         Me.Label1.TabIndex = 34
    64.         Me.Label1.Text = "PC / IP:"
    65.         Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
    66.         '
    67.         'btn_env
    68.         '
    69.         Me.btn_env.BackColor = System.Drawing.Color.White
    70.         Me.btn_env.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    71.         Me.btn_env.Location = New System.Drawing.Point(224, 8)
    72.         Me.btn_env.Name = "btn_env"
    73.         Me.btn_env.Size = New System.Drawing.Size(51, 88)
    74.         Me.btn_env.TabIndex = 33
    75.         Me.btn_env.Text = "Enviar"
    76.         '
    77.         'msg_net
    78.         '
    79.         Me.msg_net.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    80.         Me.msg_net.Location = New System.Drawing.Point(80, 32)
    81.         Me.msg_net.Multiline = True
    82.         Me.msg_net.Name = "msg_net"
    83.         Me.msg_net.Size = New System.Drawing.Size(139, 64)
    84.         Me.msg_net.TabIndex = 32
    85.         Me.msg_net.Text = ""
    86.         '
    87.         'ip
    88.         '
    89.         Me.ip.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    90.         Me.ip.Location = New System.Drawing.Point(80, 8)
    91.         Me.ip.Name = "ip"
    92.         Me.ip.Size = New System.Drawing.Size(139, 20)
    93.         Me.ip.TabIndex = 31
    94.         Me.ip.Text = ""
    95.         '
    96.         'Form2
    97.         '
    98.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    99.         Me.ClientSize = New System.Drawing.Size(288, 110)
    100.         Me.Controls.Add(Me.Label2)
    101.         Me.Controls.Add(Me.Label1)
    102.         Me.Controls.Add(Me.btn_env)
    103.         Me.Controls.Add(Me.msg_net)
    104.         Me.Controls.Add(Me.ip)
    105.         Me.Name = "Form2"
    106.         Me.Text = "Form2"
    107.         Me.ResumeLayout(False)
    108.  
    109.     End Sub
    110.  
    111. #End Region
    112.  
    113.     Private Sub btn_env_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_env.Click
    114.         Dim ip, message
    115.         ip = Me.ip.Text
    116.         message = Me.msg_net.Text
    117.         Shell("net send " & ip & message)
    118.     End Sub
    119. End Class

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    Sorry! A little change!

    VB Code:
    1. Private Sub btn_env_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_env.Click
    2.         Dim ip, message
    3.         ip = Me.ip.Text
    4.         message = Me.msg_net.Text
    5.         Shell("net send " & ip & " " & message)
    6.     End Sub

    This is what i have!
    I'm not getting any errors and the net send is working!
    All I want is a list of the Network computers!

    Or a list in a combobox where we select the computer we want to send the message to.

    Thanks for your attention!

  9. #9
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    Check out post 3. This looks like it will work.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    Can you answer my question?
    According to 1st line: 'Imports System.Runtime.InteropServices'

    I've to add the reference 'System.Runtime.InteropServices' to my project, right?
    But I can't find it on the list.

  11. #11
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    You don't need to add a referance.
    Just import System.Runtime.InteropServices.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    How can i do that?

  13. #13
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    Very first line of the code:
    VB Code:
    1. Imports System.Runtime.InteropServices
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    OK!!! So...

    And what about 'ByRef'? Why it appear underlined?
    It seems not to work.

  15. #15
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    Post the code.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    What's in red is blue underlined in VB .Net 2003:

    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Module Module2
    4.  
    5.     Structure Computer_info_101
    6.  
    7.         Public Platform_ID As Integer
    8.  
    9.         <MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String
    10.  
    11.         Public Version_Major As Integer
    12.  
    13.         Public Version_Minor As Integer
    14.  
    15.         Public Type As Integer
    16.  
    17.         <MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String
    18.  
    19.     End Structure
    20.  
    21.     Declare Unicode Function NetServerEnum Lib "Netapi32.dll" ()
    22. [COLOR=Red][B]([/B][/COLOR]ByVal Servername As Integer, ByVal level As Integer, _ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _ByVal ServerType As Integer, ByVal DomainName As String, _ByRef ResumeHandle As Integer) As Integer
    23.  
    24.     Declare Function NetApiBufferFree Lib "Netapi32.dll" ()
    25.  
    26. [COLOR=Red][B]([/B][/COLOR]ByVal lpBuffer As Integer) As Integer
    27.  
    28.     Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers
    29.  
    30.     Sub Main()
    31.  
    32.         Dim ComputerInfo As Computer_info_101
    33.  
    34.         Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As Integer
    35.  
    36.         Dim BufPtr As Integer
    37.  
    38.         Dim iPtr As IntPtr
    39.  
    40.         MaxLenPref = -1
    41.  
    42.         level = 101
    43.  
    44.         ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries, SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup name
    45.  
    46.         If ret <> 0 Then
    47.  
    48.             Console.WriteLine("An Error has occured")
    49.  
    50.             Return
    51.  
    52.         End If
    53.  
    54.  
    55.  
    56.         ' loop thru the entries
    57.  
    58.         For i = 0 To EntriesRead - 1
    59.  
    60.             ' copy the stuff into our structure
    61.  
    62.             Dim ptr As IntPtr = New IntPtr([COLOR=Red][B]BufPtr[/B][/COLOR])
    63.  
    64.             ComputerInfo = CType(Marshal.PtrToStructure(ptr, GetType(Computer_info_101)), Computer_info_101)
    65.  
    66.             BufPtr = BufPtr + Len(ComputerInfo)
    67.  
    68.             Console.WriteLine(computerInfo.Name)
    69.  
    70.         Next
    71.  
    72.         NetApiBufferFree(BufPtr)
    73.  
    74.         Console.Write("Press Enter to End")
    75.  
    76.         Dim s As String = Console.ReadLine()
    77.  
    78.     End Sub
    79. End Module

    Why is this hapening?? Can you explain?

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    OK! I changed the code and now it's all right!

    Here's the code:
    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Module Module2
    4.  
    5.     Structure Computer_info_101
    6.         Public Platform_ID As Integer
    7.         <MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String
    8.         Public Version_Major As Integer
    9.         Public Version_Minor As Integer
    10.         Public Type As Integer
    11.         <MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String
    12.  
    13.     End Structure
    14.  
    15.     Declare Unicode Function NetServerEnum Lib "Netapi32.dll" (ByVal Servername As Integer, ByVal level As Integer, ByRef buffer As Integer, ByVal PrefMaxLen As Integer, ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, ByVal ServerType As Integer, ByVal DomainName As String, ByRef ResumeHandle As Integer) As Integer
    16.     Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Integer) As Integer
    17.     Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers
    18.  
    19.     Sub Main()
    20.  
    21.         Dim ComputerInfo As Computer_info_101
    22.         Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As Integer
    23.         Dim BufPtr As Integer
    24.         Dim iPtr As IntPtr
    25.  
    26.         MaxLenPref = -1
    27.  
    28.         level = 101
    29.  
    30.         ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries, SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup name
    31.  
    32.         If ret <> 0 Then
    33.  
    34.             Console.WriteLine("An Error has occured")
    35.  
    36.             Return
    37.  
    38.         End If
    39.  
    40.         ' loop thru the entries
    41.  
    42.         For i = 0 To EntriesRead - 1
    43.  
    44.             ' copy the stuff into our structure
    45.  
    46.             Dim ptr As IntPtr = New IntPtr(BufPtr)
    47.  
    48.             ComputerInfo = CType(Marshal.PtrToStructure(ptr, GetType(Computer_info_101)), Computer_info_101)
    49.  
    50.             BufPtr = BufPtr + Len(ComputerInfo)
    51.  
    52.             Console.WriteLine(ComputerInfo.Name)
    53.  
    54.         Next
    55.  
    56.         NetApiBufferFree(BufPtr)
    57.  
    58.         Console.Write("Press Enter to End")
    59.  
    60.         Dim s As String = Console.ReadLine()
    61.  
    62.     End Sub
    63. End Module

    Sorry about the ignorance!

    And now? How can I use the module? How can I apply it to a ListBox???

  18. #18
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Listing Network Computers

    You'll want to change it to a function instead of a sub. And you don't want the name to be main, change it to something meaningful. And you are changing it to a function to return a value, in your case you will probably want a string array. Then instead of writing to the console you will insert it into the array, and return that array.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    22

    Re: Listing Network Computers

    Quote Originally Posted by mpdeglau
    You'll want to change it to a function instead of a sub. And you don't want the name to be main, change it to something meaningful. And you are changing it to a function to return a value, in your case you will probably want a string array. Then instead of writing to the console you will insert it into the array, and return that array.
    Can you tell me how to do it?
    I'm not an expert on VB .Net!!!!

    Thanks for all! I've been learning many things with you!
    Microbyte!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width