Hello,
I am completely new to the Visual Basic langauge -although I know VBScript pretty well.
I am working a making a tool that connects to a remote machine and gathers some statistics from the network adapter. However, I have no clue as to how to connect to a remote machine. I tried looking for code examples, but I couldnt find anything (which doesnt suprise me because I dont really know what to look for) ![]()
In VBScript I would probably use WMI -is that also true in VB If so, how do I use it in VB If not, what should I be looking at Any code examples or help that you can give would be very appreciated ![]()
Regards,
Jeremy

How to retreive network adpater information from remote machine
Matt Stum
lenak
Wonderful! That did it. Thank you very much. By the way, what is the function of adding this reference What does it accomplish....I have been reading a lot of VB books and havent run into anything mentioning this subject.
Anyway, once again, thank you !
Jeremy
djchapin
Hello again,
I was taking another look at your reply and was wondering what you meant by 'import the System.Management' namespace
I have seen some code that has the 'import.......(something)' lines but never understood how or when to use them. Any chance you provide an example and short explanation (I would owe you a round of beers
)
Thanks again,
jeremy
Donald E. King
here is some code which displays the Network Adapters' names on the remote computer:
'Import the System.Management and System.Management.Instrumentation namespace
..
..
Dim theScope as new ManagementScope("\\computerName\root\cimv2")
Dim theQuery as new ObjectQuery("SELECT * FROM Win32_NetworkAdapter")
Dim theSearcher as new ManagementObjectSearcher(theScope, theQuery)
Dim theCollectionOfResults as ManagementObjectCollection = theSearcher.Get()
for each currentResult as ManagementObject in theCollectionOfResults
MessageBox.Show(currentResult("Name").ToString())
next
you can retrieve other bits of information, such as the manufacturer/MAC Address etc... by replace the indexer appropriate, so instead of "Name" you could put in "Manufacturer" to get the manaufacturer of the network adapter.
does this help/work for you Remember, the code will change slightly depending on what you want to obtain from the network adapter
Krenshau
you need to import the System.Management namespace.
in doubt, just reference them with the full namespace path, example:
System.Management.ManagementScope.............
System.Management.ObjectQuery.........
etc....
moerderin
The import syntax means to include the accessibility of a namespace given. Advantage being that you don't have to use the long namespace. Example:
System.Text.StringBuilder
instead of writing all that, just add at the top of your class "Imports System.Text" (without quotes) and then you can just type in the class name in that namespace, in this case, StringBuilder.
so at the top of the class for this WMI example, add:
imports System.Management
imports System.Management.Instrumentation
and you should be good to go
Cthy651
Hello,
Thank you. I think I am finally beginning to catch on. Sorry, got a couple more questions: I took the code you gave me and pasted it into my project (which is just a form with a button on it at the moment) to test the output, however, I am getting some errors
Error 1 Type 'ManagementScope' is not defined.
Error 2 Type 'ObjectQuery' is not defined.
Error 3 Type 'ManagementObjectSearcher' is not defined.
Error 4 Type 'ManagementObjectCollection' is not defined.
Error 5 Type 'ManagementObject' is not defined.
It seems that I get these kinds of errors quite often whenever I am trying to do something. I am wondering if there is some setting that needs to be changed in the IDE , or is it that I need to declare something, or did I not do something properly
Thanks yet again,
Jeremy
maverick_majnoo
you would probably use WMI For this. It can be done.
Take a look at the Management classes in the System.Management.Instrumentation namespace, whilst I write some code for you
What information do you want to collect from the network adapters
Lixin wang
Gentlemen,
Thank you both very much! This is exactly what I was looking for
. I was just having a hardtime figuring out what the syntax for connecting to remote machines was and had no clue as to where to look.
Thank you for the code example....it will help me very much. And, thank you for the links to examples -it looks like they will be a big help.
I am sure I will ask more questions.....but, until then.....
Regards,
Jeremy
Golden Strands
Summoner
Hi,
Ok, I gave that a try and am still coming up with the same errors. I tried adding both the 'system.management.' & 'system.management.instrumentation' in front of the references. So, I suspect I am doing something wrong (I also added in 'Imports System' in hopes that it might help) Here is my code:
Imports System
Imports System.Management
Imports System.Management.Instrumentation
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim theScope As New System.Management.ManagementScope("\\127.0.0.1\root\cimv2")
Dim theQuery As New System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapter")
Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
For Each currentResult As ManagementObject In theCollectionOfResults
MessageBox.Show(currentResult("Name").ToString())
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If My.Computer.Network.Ping("127.0.0.1") Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
End Sub
End Class
Pretty simple code, but still keeps throwing the same errors. I am just wondering what I have missed
Once again, thanks for your help,
Jeremy
Kenneth Gillen
Examples are some of the best way to learn. Check out some of the VB/C# examples for the basic operations or some more robust examples as found in the Starter Kits. Also there are 101 Samples for Visual Studio 2005 which is a robust, initial development tasks to more involved tasks for winforms, web development etc.
Note in the 101 Samples, there is a network example that gets information you are looking for, on a local machine, but one could use that code on a remote and remote the information back to your consumer on a different machine.