|
-
Mar 9th, 2006, 04:25 PM
#1
Thread Starter
Junior Member
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!
-
Mar 9th, 2006, 04:58 PM
#2
Frenzied Member
Re: Listing Network Computers
-
Mar 11th, 2006, 10:43 AM
#3
Thread Starter
Junior Member
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!
-
Mar 11th, 2006, 10:51 AM
#4
Frenzied Member
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.
-
Mar 11th, 2006, 10:55 AM
#5
Thread Starter
Junior Member
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.
-
Mar 11th, 2006, 11:06 AM
#6
Frenzied Member
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.
-
Mar 11th, 2006, 11:13 AM
#7
Thread Starter
Junior Member
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:
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents msg_net As System.Windows.Forms.TextBox
Friend WithEvents ip As System.Windows.Forms.TextBox
Friend WithEvents btn_env As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.btn_env = New System.Windows.Forms.Button
Me.msg_net = New System.Windows.Forms.TextBox
Me.ip = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Label2
'
Me.Label2.BackColor = System.Drawing.Color.Transparent
Me.Label2.ForeColor = System.Drawing.Color.Black
Me.Label2.Location = New System.Drawing.Point(8, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 35
Me.Label2.Text = "Mensagem:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.ForeColor = System.Drawing.Color.Black
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 16)
Me.Label1.TabIndex = 34
Me.Label1.Text = "PC / IP:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btn_env
'
Me.btn_env.BackColor = System.Drawing.Color.White
Me.btn_env.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.btn_env.Location = New System.Drawing.Point(224, 8)
Me.btn_env.Name = "btn_env"
Me.btn_env.Size = New System.Drawing.Size(51, 88)
Me.btn_env.TabIndex = 33
Me.btn_env.Text = "Enviar"
'
'msg_net
'
Me.msg_net.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.msg_net.Location = New System.Drawing.Point(80, 32)
Me.msg_net.Multiline = True
Me.msg_net.Name = "msg_net"
Me.msg_net.Size = New System.Drawing.Size(139, 64)
Me.msg_net.TabIndex = 32
Me.msg_net.Text = ""
'
'ip
'
Me.ip.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.ip.Location = New System.Drawing.Point(80, 8)
Me.ip.Name = "ip"
Me.ip.Size = New System.Drawing.Size(139, 20)
Me.ip.TabIndex = 31
Me.ip.Text = ""
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(288, 110)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btn_env)
Me.Controls.Add(Me.msg_net)
Me.Controls.Add(Me.ip)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btn_env_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_env.Click
Dim ip, message
ip = Me.ip.Text
message = Me.msg_net.Text
Shell("net send " & ip & message)
End Sub
End Class
-
Mar 11th, 2006, 11:21 AM
#8
Thread Starter
Junior Member
Re: Listing Network Computers
Sorry! A little change!
VB Code:
Private Sub btn_env_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_env.Click
Dim ip, message
ip = Me.ip.Text
message = Me.msg_net.Text
Shell("net send " & ip & " " & message)
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!
-
Mar 11th, 2006, 11:38 AM
#9
Frenzied Member
Re: Listing Network Computers
Check out post 3. This looks like it will work.
-
Mar 11th, 2006, 12:00 PM
#10
Thread Starter
Junior Member
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.
-
Mar 11th, 2006, 04:31 PM
#11
Frenzied Member
Re: Listing Network Computers
You don't need to add a referance.
Just import System.Runtime.InteropServices.
-
Mar 11th, 2006, 04:45 PM
#12
Thread Starter
Junior Member
Re: Listing Network Computers
How can i do that?
-
Mar 11th, 2006, 05:27 PM
#13
Frenzied Member
Re: Listing Network Computers
Very first line of the code:
VB Code:
Imports System.Runtime.InteropServices
-
Mar 11th, 2006, 05:30 PM
#14
Thread Starter
Junior Member
Re: Listing Network Computers
OK!!! So...
And what about 'ByRef'? Why it appear underlined?
It seems not to work.
-
Mar 11th, 2006, 05:40 PM
#15
Frenzied Member
Re: Listing Network Computers
-
Mar 11th, 2006, 05:51 PM
#16
Thread Starter
Junior Member
Re: Listing Network Computers
What's in red is blue underlined in VB .Net 2003:
VB Code:
Imports System.Runtime.InteropServices
Module Module2
Structure Computer_info_101
Public Platform_ID As Integer
<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String
Public Version_Major As Integer
Public Version_Minor As Integer
Public Type As Integer
<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String
End Structure
Declare Unicode Function NetServerEnum Lib "Netapi32.dll" ()
[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
Declare Function NetApiBufferFree Lib "Netapi32.dll" ()
[COLOR=Red][B]([/B][/COLOR]ByVal lpBuffer As Integer) As Integer
Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers
Sub Main()
Dim ComputerInfo As Computer_info_101
Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As Integer
Dim BufPtr As Integer
Dim iPtr As IntPtr
MaxLenPref = -1
level = 101
ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries, SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup name
If ret <> 0 Then
Console.WriteLine("An Error has occured")
Return
End If
' loop thru the entries
For i = 0 To EntriesRead - 1
' copy the stuff into our structure
Dim ptr As IntPtr = New IntPtr([COLOR=Red][B]BufPtr[/B][/COLOR])
ComputerInfo = CType(Marshal.PtrToStructure(ptr, GetType(Computer_info_101)), Computer_info_101)
BufPtr = BufPtr + Len(ComputerInfo)
Console.WriteLine(computerInfo.Name)
Next
NetApiBufferFree(BufPtr)
Console.Write("Press Enter to End")
Dim s As String = Console.ReadLine()
End Sub
End Module
Why is this hapening?? Can you explain?
-
Mar 11th, 2006, 05:55 PM
#17
Thread Starter
Junior Member
Re: Listing Network Computers
OK! I changed the code and now it's all right!
Here's the code:
VB Code:
Imports System.Runtime.InteropServices
Module Module2
Structure Computer_info_101
Public Platform_ID As Integer
<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String
Public Version_Major As Integer
Public Version_Minor As Integer
Public Type As Integer
<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String
End Structure
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
Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Integer) As Integer
Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers
Sub Main()
Dim ComputerInfo As Computer_info_101
Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As Integer
Dim BufPtr As Integer
Dim iPtr As IntPtr
MaxLenPref = -1
level = 101
ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries, SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup name
If ret <> 0 Then
Console.WriteLine("An Error has occured")
Return
End If
' loop thru the entries
For i = 0 To EntriesRead - 1
' copy the stuff into our structure
Dim ptr As IntPtr = New IntPtr(BufPtr)
ComputerInfo = CType(Marshal.PtrToStructure(ptr, GetType(Computer_info_101)), Computer_info_101)
BufPtr = BufPtr + Len(ComputerInfo)
Console.WriteLine(ComputerInfo.Name)
Next
NetApiBufferFree(BufPtr)
Console.Write("Press Enter to End")
Dim s As String = Console.ReadLine()
End Sub
End Module
Sorry about the ignorance!
And now? How can I use the module? How can I apply it to a ListBox???
-
Mar 11th, 2006, 11:12 PM
#18
Frenzied Member
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.
-
Mar 12th, 2006, 02:45 PM
#19
Thread Starter
Junior Member
Re: Listing Network Computers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|