Solved

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

Posted on 2004-08-05
4
1,082 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

20 Experts available now in Live!

Get 1:1 Help Now