WMI query

N

NetworkElf

I've been trying to run a simple query to get the amount of memory on my
machine using WMI. However, I seem to be running into a snag. When I hit the
mem = queryObj("MaxCapacity") line, I get an error of "A first chance
exception of type 'System.Management.ManagementException' occurred in
System.Management.dll."

I only seem to get this on non-string returns. If I remove the reference to
MaxCapacity and just ask it to return the tag, it works fine.

Could someone point out what I'm missing here?

Thank you,

ne.

Dim mem As UInt32 = 0

Try

Dim searcher As New Management.ManagementObjectSearcher("select
* from Win32_physicalmemory")

For Each queryObj As Management.ManagementObject In
searcher.Get()

mem = queryObj("MaxCapacity")

MsgBox(queryObj("tag") & " size: " & Convert.ToString(mem))

Next

Catch ex As Exception

End Try
 
M

Matthias Tacke

NetworkElf said:
I've been trying to run a simple query to get the amount of memory on my
machine using WMI. However, I seem to be running into a snag. When I hit the
mem = queryObj("MaxCapacity") line, I get an error of "A first chance
exception of type 'System.Management.ManagementException' occurred in
System.Management.dll."

I only seem to get this on non-string returns. If I remove the reference to
MaxCapacity and just ask it to return the tag, it works fine.

Could someone point out what I'm missing here?

Thank you,
I can find MaxCapacity property only in Win32_PhysicalMemoryArray

not in Win32_PhysicalMemory
 
N

Newbie Coder

Network Elf,

Imports System.Management


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim searcher As New ManagementObjectSearcher( "root\CIMV2", _
"SELECT * FROM Win32_PhysicalMemoryArray")
Dim strMemory As String
For Each queryObj As ManagementObject In searcher.Get()

Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_PhysicalMemoryArray instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("MaxCapacity: {0}",
queryObj("MaxCapacity"))
strMemory = Convert.ToString(queryObj("MaxCapacity"))
MessageBox.Show("Maximum Capacity: " & strMemory, _
Me.Text, MessageBoxButtons.OK,
MessageBoxIcon.Information)
Next
Catch err As ManagementException
MessageBox.Show("Error: " & err.Message)
End Try
End Sub

I hope this helps,
 
N

NetworkElf

Newbie et al.,

I found a lot of what I needed, including the physical memory available to
the OS in Win32_operatingsystem. Those calls seem to be working well so far.

Now, if I understand WMI correctly, I should be able to pull information out
of the BIOS as well. Since most of our systems have the serial numbers
embedded in the BIOS, I'd like to get that.

If you haven't guessed it, we have thousands of systems and no accurate
inventory. I've found the basics of what I need, but I'm still looking for
the elusive hardware information.

Thanks for your help guys.

ne.
 
N

NetworkElf

OK, I found CIM_Product. From this I can get a Vendor, an IdentifyingNumber
(serial) and a Name (product name it seems). However, this returns all
products both software and hardware on the target system. I thought about
sorting by manufacturer's name, but that is rather perilous, as any given
manufacturer may produce both hardware and software or multiple types of
hardware etc. This could get very messy and inaccurate in a hurry.

So, the question is this: Is there a version of CIM_Product which only pulls
information from the physical computer system? The BIOS will give me a
vendor/manufacturer and a serial number, but I cannot seem to fins a
parameter for model. IOW, I want to be able to find out that a system is a
Dell, PowerEdge 2450, Serial # XYZ1234A...

Right now, the cleanest method I can think of is to use CIM_BIOSelement to
get the serial number of the box, then use that to weed out the manufacturer
and model from the information in CIM_Product. While this would work, it
strikes me as being rather kludgy.

Any thoughts?

Thanks,

ne.
 
L

Linda Liu [MSFT]

Hi Ne,

How about querying the Win32_ComputerSystemProduct and Win32_ComputerSystem
classes?

The Win32_ComputerSystemProduct class is based on the CIM_Product class,
and only contains hardware information of the machine.

The Win_ComputerSystem class contains a property named Model, which is what
you want.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
N

NetworkElf

Linda Liu said:
Hi Ne,

How about querying the Win32_ComputerSystemProduct and
Win32_ComputerSystem
classes?

The Win32_ComputerSystemProduct class is based on the CIM_Product class,
and only contains hardware information of the machine.

The Win_ComputerSystem class contains a property named Model, which is
what
you want.

Thank you, Linda. I'll take a look at it. Though, IIRC, I looked before.
What I'm trying to collect is info on just the hardware itself. My hope was
to get the 3 items from a single place. However, in the grand scheme of
things, it's not really going to make that much difference if I have to pull
the data from more than one source. For what this program is going to be
doing, I doubt it'll make much of a speed difference.

Thanks,

ne.
 
N

NetworkElf

NetworkElf said:
Thank you, Linda. I'll take a look at it. Though, IIRC, I looked before.
What I'm trying to collect is info on just the hardware itself. My hope
was to get the 3 items from a single place. However, in the grand scheme
of things, it's not really going to make that much difference if I have to
pull the data from more than one source. For what this program is going to
be doing, I doubt it'll make much of a speed difference.

That was it. Thank you very much Linda!
 

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

Top