473,545 Members | 2,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check item in collection in WMI ManagementObjec t

Hello,

Im using WMI to get CPU information through Win32_Processor .
It returns a collection but some items are "not valid".

.....
foreach( ManagementObjec t oReturn in oReturnCollecti on )
{
Console.WriteLi ne(oReturn["Manufactur er"].ToString());
Console.WriteLi ne(oReturn["ProcessorI d"].ToString());
}

If oReturn["ProcessorI d"] does not "exist" it crash with error:
Additional information: Object reference not set to an instance of an object.

How can I test to see if oReturn["ProcessorI d"] is set to an instance
befor I WriteLine(...) it?

Thanks,

Joao Rego

Dec 22 '05 #1
3 12581
Hi,

I had the same problem, use

if (oReturn["ProcessorI d"] != null)
<read operations here>

Cheers

--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Joao Rego" wrote:
Hello,

Im using WMI to get CPU information through Win32_Processor .
It returns a collection but some items are "not valid".

....
foreach( ManagementObjec t oReturn in oReturnCollecti on )
{
Console.WriteLi ne(oReturn["Manufactur er"].ToString());
Console.WriteLi ne(oReturn["ProcessorI d"].ToString());
}

If oReturn["ProcessorI d"] does not "exist" it crash with error:
Additional information: Object reference not set to an instance of an object.

How can I test to see if oReturn["ProcessorI d"] is set to an instance
befor I WriteLine(...) it?

Thanks,

Joao Rego

Dec 22 '05 #2
Joao,

what if you first read the property in a object variable and check this
variable for *null* before printing it out?
--

Stoitcho Goutsev (100) [C# MVP]

"Joao Rego" <Jo******@discu ssions.microsof t.com> wrote in message
news:2F******** *************** ***********@mic rosoft.com...
Hello,

Im using WMI to get CPU information through Win32_Processor .
It returns a collection but some items are "not valid".

....
foreach( ManagementObjec t oReturn in oReturnCollecti on )
{
Console.WriteLi ne(oReturn["Manufactur er"].ToString());
Console.WriteLi ne(oReturn["ProcessorI d"].ToString());
}

If oReturn["ProcessorI d"] does not "exist" it crash with error:
Additional information: Object reference not set to an instance of an
object.

How can I test to see if oReturn["ProcessorI d"] is set to an instance
befor I WriteLine(...) it?

Thanks,

Joao Rego

Dec 22 '05 #3
OK... that's it... thanks for your help.

"Salvador" wrote:
Hi,

I had the same problem, use

if (oReturn["ProcessorI d"] != null)
<read operations here>

Cheers

--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Joao Rego" wrote:
Hello,

Im using WMI to get CPU information through Win32_Processor .
It returns a collection but some items are "not valid".

....
foreach( ManagementObjec t oReturn in oReturnCollecti on )
{
Console.WriteLi ne(oReturn["Manufactur er"].ToString());
Console.WriteLi ne(oReturn["ProcessorI d"].ToString());
}

If oReturn["ProcessorI d"] does not "exist" it crash with error:
Additional information: Object reference not set to an instance of an object.

How can I test to see if oReturn["ProcessorI d"] is set to an instance
befor I WriteLine(...) it?

Thanks,

Joao Rego

Dec 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
10099
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
3
5161
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form within the html document. When the Finish button is clicked, I need to check for any empty input boxes before loading the next aspx page...but it...
7
2438
by: Neil | last post by:
I have a check box on a form that's bound to a function that returns a True/False value. When the user clicks on the check box, I run some code through the MouseDown event. Everything works fine. Only problem is: when the user clicks on it, there's a beep, and then they get a status bar message: "Control can't be edited; it's bound to the...
18
4714
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
2
3079
by: jmhmaine | last post by:
I've created a lookup class for a windows form application and I'm stuck on how on using the collection object. The process is simple, if the item is in the collection then return that object, if the item is not in the collection then create the item from a value in the database, then return it. Here is the code: Imports...
0
1918
by: Chris Fink | last post by:
I am looking for all the string indexers for the ManagementObject collection and do not know where in the MSDN documentation to find them. Name and Description are two of them, but I would like a list of the other available items. Specifically, I am looking for a way to retrieve the name of a DVD Movie when it is inserted into the...
3
8707
by: Bmack500 | last post by:
I have a sub, and a class. The sub is like this: Sub dothis() Dim aInfoListX As New infoWrapperClass aInfoListX.params = ReadConfig() Dim sqlCMD As New SqlCommand aInfoListX.sqlCmd = sqlCMD aInfoListX.sqlConn = New SqlClient.SqlConnection(aInfoListX.params.sqlserver) End Sub
2
9859
by: AdawayNoSpam | last post by:
Said that I have the following class Class MyRootClass(Of T) End Class Class MySubClass1(Of T) Inherits MyRootClass(Of T) End Class
1
2166
by: jkinneberg | last post by:
In the process of developing a C# GUI for our desktop support team. Basic code following allows me to query the contents of a collection. Would someone help me by posting a sample of how to add workstations to a collection. Thanks --------------------------------------------------------------------- const string sSMSCollectionProject2003...
0
7470
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7659
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7811
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5334
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3455
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1887
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.