我对WMI查询有点问题。 我必须检查WMI查询实例中是否存在某个属性,我所做的代码是:
Imports System.Management
Imports System.Management.Instrumentation
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim search_cpu As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
Dim info_cpu As ManagementObject '= Convert.ToUInt32("search_cpu")
Dim cpu_v As Integer
For Each info_cpu In search_cpu.Get()
If search_cpu.Get("caption") = True Then
cpu_v = "Caption"
Label1.Text = ("Name: " & info_cpu(cpu_v).ToString())
End If
Next
End Sub
End Class
任何帮助将不胜感激。 提前致谢
答案 0 :(得分:0)
我设法重现。以下代码适用于我,Label1现在显示:
Intel64 Family 6 Model 58 Stepping 9
Sub Main()
Dim search_cpu As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
Dim info_cpu As ManagementObject '= Convert.ToUInt32("search_cpu")
Dim caption As String
For Each info_cpu In search_cpu.Get()
caption = info_cpu("caption").ToString()
Next
Label1.Text = caption
if (string.isnullorempty(caption))
Label1.Text ="<does not exist>"
End Sub