Search code examples
vb.netwinapiintwmioutput

Finding Chassis Type Using VB.Net


I'm trying to find the chassis types of various computers using VB.NET. This is going to be part of an automated testing program that uses certain criteria to determine a routine. The code I am using is as follows

'REFERENCING WIN32_SystemEnclosure
Dim qwin32SystemEnclosure As New SelectQuery("Win32_SystemEnclosure")
Dim searchse As New ManagementObjectSearcher(qwin32SystemEnclosure)
Dim infose As New ManagementObject

For Each infose In searchse.Get
    strCOMM = infose("chassisTypes").ToString
Next

And I receive system.Uint16[] as a result. I know that I am using the right win_32 class. I believe there is something wrong with the output going to the string, but I can not figure out how to correct. For reference, the correct output should be 10.

I appreciate the help!

EDIT: I'm having trouble with a similar issue... I am not able to convert uint32 into string or integer like I was able to with uint16 values. Here is my code

Imports System.Management
Public Class frmBatterytest
Dim strDesigncap As String
Dim strCurrentcap As String
Dim strResult As String = 0
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
    ' REFERENCING WIN32_BATTERY
    Dim qwin32 As New SelectQuery("Win32_Battery")
    Dim search As New ManagementObjectSearcher(qwin32)
    Dim info As New ManagementObject

    For Each info In search.Get
        strDesigncap = info("DesignCapacity")(0).ToString
        strCurrentcap = info("FullChargeCapacity")(0).ToString
    Next

    lblDCv.Text = strDesigncap
    lblCCv.Text = strCurrentcap
    lblTRv.Text = strCurrentcap / strDesigncap * 100 & "%"

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

End Class

Solution

  • "system.Uint16[]" is the result of calling ToString on an array type, it will not automatically format the values in the array and return them as a string to you.

    Pull a specific value:

     strCOMM = infose("chassisTypes")(0).ToString
    

    Or Join() to get all values in a delimited string.