我试图使用VB.NET查找各种计算机的机箱类型。这将成为使用某些标准来确定例程的自动化测试程序的一部分。我使用的代码如下
'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
结果我收到了system.Uint16[]
。我知道我正在使用正确的win_32 class
。我相信输出到字符串有问题,但我无法弄清楚如何纠正。作为参考,正确的输出应为10。
我很感激帮助!
编辑:我遇到类似问题的麻烦......我无法将uint32转换为字符串或整数,就像我能够使用uint16值一样。这是我的代码
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
答案 0 :(得分:1)
拉出特定值: 或"system.Uint16[]"
是在数组类型上调用ToString
的结果,它不会自动格式化数组中的值并将它们作为字符串返回给您。< / p>
strCOMM = infose("chassisTypes")(0).ToString
Join()
获取分隔字符串中的所有值。