VB.Net (VB2010)怎么使用WMI来获取CPU型号?

2024-12-02 22:05:01
推荐回答(1个)
回答1:

Imports System
Imports System.Management
Module Module1

    Sub Main()
        Dim scope As New ManagementScope("\\.\root\cimv2")
        scope.Connect()
        Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_Processor")
        Dim searcher As New ManagementObjectSearcher(scope, objectQuery)
        Dim cpu As ManagementObject

        For Each cpu In searcher.Get()
            Console.WriteLine("Processor: " & cpu("Name"))
            Console.WriteLine("Manufacturer: " & cpu("Manufacturer"))
            Console.WriteLine("Clock frequency: " & cpu("MaxClockSpeed") & " MHz")
            Console.WriteLine("NumberOfLogicalProcessors: " & cpu("NumberOfLogicalProcessors"))
            Console.WriteLine("NumberOfCores: " & cpu("NumberOfCores"))
            Console.WriteLine()
        Next cpu

        Console.WriteLine()
        Console.WriteLine("Press any key to quit")
        Console.ReadKey()
    End Sub

End Module