返回异常的 WMI 查询

本文关键字:查询 WMI 异常 返回 | 更新日期: 2023-09-27 18:36:43

我正在尝试使用 WMI 查询访问我的 CPU 温度,因为人们说你可以做到。我正在使用我在线的脚本,当我尝试输出查询的数据时,它只是给了我不受支持的线程。下面是错误输出:

System.Management.ManagementObjectCollectionA first chance exception of type 'System.Management.ManagementException' occurred in System.Management.dll
The thread 0xc8ac has exited with code 259 (0x103).
A first chance exception of type 'System.Management.ManagementException' occurred in System.Management.dll
An error occurred while querying for WMI data: Not supported System.Management.ManagementObjectCollectionAn error occurred while querying for WMI data: Not supported The thread 0x9928 has exited with code 259 (0x103).
A first chance exception of type 'System.Management.ManagementException' occurred in System.Management.dll
System.Management.ManagementObjectCollectionAn error occurred while querying for WMI data: Not supported The program '[49728] GetHardwareInfo.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[49728] GetHardwareInfo.vshost.exe' has exited with code 0 (0x0).

我会假设这是因为没有数据,但我不确定。

private void get_cpu_temp()
{
    try
    {
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root'WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature");
        Console.Write(searcher.Get());
        foreach (ManagementObject queryObj in searcher.Get())
        {
            double temp = double.Parse(queryObj["CurrentTemperature"].ToString());
            temp = (temp - 2732) / 10d;
            Console.Write(temp.ToString());
        }
    }
    catch (ManagementException err)
    {
        Console.Write("An error occurred while querying for WMI data: " + err.Message);
    }
}

返回异常的 WMI 查询

正如我在 CPU 温度监控中提到的,您的主板必须支持通过 WMI 查询 CPU 温度。

在这种情况下,看起来您的主板不支持通过 WMI 进行查询,因此它根本不适合您。

并非所有计算机都支持读取 CPU 温度。这是您的 BIOS 软件的功能。有时,BIOS 制造商会提供 DLL 文件,您可以引用这些文件来调用所需的函数并返回详细信息。重新启动计算机时,请获取 BIOS 制造商和型号,并检查它们是否支持它。

MSAcpi_ThermalZoneTemperature不支持。.