Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems getting NetworkInterface information using WMI with VB.NET.

Posted on 2006-07-14
5
Medium Priority
?
1,830 Views
Last Modified: 2012-06-27
I am successfully getting logical disk, memory, processor, etc information using WMI on a Windows XP SP2 computer. I am also getting the server uptime using:
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * From Win32_PerfFormattedData_PerfOS_System")
 
For Each objOS in colOperatingSystems
    intSystemUptime = Int(objOS.SystemUpTime / 60)
    Wscript.Echo intSystemUptime & " minutes"
Next

but when I use

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface",,48)
For Each objItem in colItems
    Wscript.Echo "BytesReceivedPersec: " & objItem.BytesReceivedPersec
    Wscript.Echo "BytesSentPersec: " & objItem.BytesSentPersec
    Wscript.Echo "BytesTotalPersec: " & objItem.BytesTotalPersec
    Wscript.Echo "Name: " & objItem.Name
Next

it fails... I must be missing something in my application.. Any idea on why the Win32_PerfRawData_Tcpip_NetworkInterface request would fail?
0
Comment
Question by:Sc0ttRB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 41

Expert Comment

by:graye
ID: 17110310
No, that looks right...

I suspect that your network card doesn't support the type of instrumentation that's required by WMI.

BTW: BytesTotalPerSec is a 64-bit integer...
0
 
LVL 2

Author Comment

by:Sc0ttRB
ID: 17110802
If I use Microsofts WMI Code Creator on that same machine and run a query against the Win32_PerfRawData_Tcpip_NetworkInterface I get results for the built in LAN card, a Wireless G card, a built in Wireless B and the Loopback. So the cards all support the WMI.

I am not the best programmer. Could I be missing Classes or something along those lines. I added a reference to Systems.Management and added the line Imports Systems.Management to my code.

0
 
LVL 2

Author Comment

by:Sc0ttRB
ID: 17110995
Ok.. going back to WMI Code Creator I noticed I was using VB Script and not VB.NET if I change the coding to :

Try
                Dim connection As New ConnectionOptions
                connection.Username = userNameBox.Text
                connection.Password = passwordBox.Text
                connection.Authority = "ntlmdomain:DOMAIN"

                Dim scope As New ManagementScope( _
                    "\\FullComputerName\root\CIMV2", connection)
                scope.Connect()

                Dim query As New ObjectQuery( _
                    "SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface")

                Dim searcher As New ManagementObjectSearcher(scope, query)

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_PerfFormattedData_Tcpip_NetworkInterface instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Name: {0}", queryObj("Name"))
                Next

                Close()
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            Catch unauthorizedErr As System.UnauthorizedAccessException

                MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)
            End Try

Should that work? ALso if the above is correct how to set it to access local computer and not remote (possibly nondomain pc)
0
 
LVL 41

Accepted Solution

by:
graye earned 2000 total points
ID: 17111070
That looks right to me...

To get information for the local PC, just change the "FullComputerName" to "." (just like the code creator does!)

So what do you get when you run the VB.Net application?
0
 
LVL 2

Author Comment

by:Sc0ttRB
ID: 17111230
I changed my code to use the VB.NET instead of the VB Script and success...  I want to get this data for example 5 times over 5 minutes and then average the data. How can I loop the script with a 60 sec pause before each iteration?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

604 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