Error message

  • Thread starter Thread starter Physeth
  • Start date Start date
P

Physeth

My application is attemping to access some CPU info on a
local machine, but when I run it, I get an error message
of "Object reference not set to an instance of an object."

Most of this code works-I can use other categories and
query general info, so can anyone give me a hint?


Imports System
Imports System.Management
Module Module1
Sub Main()
Dim options As New ConnectionOptions
Dim IPAddress As New Integer
Dim TheMachine As String = "10.33.32.125"
Dim MyScope As New ManagementScope("\\" &
TheMachine & "\root\cimv2")
Dim strClassNetConf1 As String
= "Win32_PerfFormattedData_PerfOS_Processor"
Dim TheFilter As New SelectQuery("SELECT * FROM "
& strClassNetConf1)
Dim MySearcher As New ManagementObjectSearcher
(MyScope, TheFilter)
Dim mObject As ManagementObject
MyScope.Connect()
For Each mObject In MySearcher.Get()
Console.WriteLine(mObject.GetPropertyValue
("Caption").ToString)
Next mObject
End Sub
End Module
 
Physeth said:
My application is attemping to access some CPU info on a
local machine, but when I run it, I get an error message
of "Object reference not set to an instance of an object."

Most of this code works-I can use other categories and
query general info, so can anyone give me a hint?


Imports System
Imports System.Management
Module Module1
Sub Main()
Dim options As New ConnectionOptions
Dim IPAddress As New Integer
Dim TheMachine As String = "10.33.32.125"
Dim MyScope As New ManagementScope("\\" &
TheMachine & "\root\cimv2")
Dim strClassNetConf1 As String
= "Win32_PerfFormattedData_PerfOS_Processor"
Dim TheFilter As New SelectQuery("SELECT * FROM "
& strClassNetConf1)
Dim MySearcher As New ManagementObjectSearcher
(MyScope, TheFilter)
Dim mObject As ManagementObject
MyScope.Connect()
For Each mObject In MySearcher.Get()
Console.WriteLine(mObject.GetPropertyValue
("Caption").ToString)


If mObject.GetPropertyValue("Caption") ever returns Nothing, you will
be attempting to call ToString on Nothing, which would give the error
message you are receiving.

I can't immediately see anywhere else you might be trying to use
Nothing; with this error, debugging and stepping through is usually
good for finding where you are trying to use Nothing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top