Solved

How to read a property array stored in a WMI class?

Posted on 2004-08-05
4
1,076 Views
Last Modified: 2012-08-13
I'm trying to read the property ChassisTypes from the  WMI class, Win32_SystemEnclosure, but am experiencing problems.  

The property itself contains a property array of type uint16, and I'm not certain how to read this in, so that i can display it.  I'm able to access non array types without any problems, but am not certain on how to go about getting the values from this array.

Could someone give me an example of how to do this in VB.NET ?  I'm completely stuck!
0
Comment
Question by:pringlet
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 11725540
This works for me

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objWMIService As Object
        Dim colchassis As Object
        Dim objchassis As Object
        Dim objItem As Object

        objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\Ronald\root\cimv2")
        colChassis = objWMIService.ExecQuery _
            ("Select * from Win32_SystemEnclosure")
        For Each objChassis In colChassis
            For Each objItem In objChassis.ChassisTypes
                MsgBox("Chassis Type: " & objItem)
            Next
        Next
    End Sub

Chassistype

1 Other
2 Unknown
3 Desktop
4 Low Profile Desktop
5 Pizza Box  
6 Mini Tower
7 Tower
8 Portable
9 Laptop
10 Notebook
11 Hand Held
12 Docking Station
13 All in One
14 Sub Notebook
15 Space-Saving
16 Lunch Box  
17 Main System Chassis
18 Expansion Chassis
19 SubChassis
20 Bus Expansion Chassis
21 Peripheral Chassis
22 Storage Chassis
23 Rack Mount Chassis
24 Sealed-Case PC
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11726077
Try:

Dim intType As Integer = Convert.ToInt32(objItem)

Bob

0
 

Author Comment

by:pringlet
ID: 11726629
Cheers

Apologies, meant to say i am using the ManagementObject type objects for this code :-

e.g

Private objOS As ManagementObjectSearcher
Private objMgmt As ManagementObject
Private m_strComputerName As String
       
               
Public Sub New()
objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

For Each objMgmt In objOS.Get
  m_strComputerName = objMgmt("csname").ToString()
  msgbox (m_strComputerName)
Next

Is anyone familiar with how to do it via this type of methodology for the array type mentioned above?  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11726702
Not exactly, but if you are trying to get Computer Name, then this is also possible:

SystemInformation.ComputerName

Bob
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now