Solved

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with error when uploading excel file 3 28
VB: Convert 2 dates to specific format 24 48
write xml in vb.net 2 24
Convert datetime to time string 10 21
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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