473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

WMI query

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
May 8 '07 #1
8 5267
NetworkElf wrote:
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


--
Greetings
Matthias
May 8 '07 #2
There is an example here that appears to have what your after, it might help
you out
http://www.codeproject.com/cs/intern...select=1811254

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

"NetworkElf" <Ne********@nospam.nospamwrote in message
news:OP**************@TK2MSFTNGP06.phx.gbl...
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


May 8 '07 #3
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,

--
Newbie Coder
(It's just a name)


"NetworkElf" <Ne********@nospam.nospamwrote in message
news:OP**************@TK2MSFTNGP06.phx.gbl...
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


May 8 '07 #4

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.
May 9 '07 #5
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.
"NetworkElf" <Ne********@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>
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.

May 9 '07 #6
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

May 10 '07 #7

"Linda Liu [MSFT]" <v-****@online.microsoft.comwrote in message
news:aH**************@TK2MSFTNGHUB02.phx.gbl...
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.
May 10 '07 #8

"NetworkElf" <Ne********@nospam.nospamwrote in message
news:um**************@TK2MSFTNGP06.phx.gbl...
>
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!
May 10 '07 #9

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

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
4
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.