Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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