WMI查询返回异常

时间:2015-01-07 22:08:58

标签: c# wmi wmi-query

我尝试使用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);
    }
}

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

来自 MSAcpi_ThermalZoneTemperature not supported.