wmi c# - WMI Giving Incorrect Voltage Readings

2019-02-28 09:46发布

问题:

So I made a program with WPF, C# and WMI as a small project to gather the specifications of a computer, and put it on SourceForge because it was of little use to me.
I soon discovered that SoftPedia had picked it up, and noticed in their screenshot that there was an error with the voltage reading. This is an image nicked from their page:

http://i.stack.imgur.com/8QpBq.png

At the moment I source the voltage by using "CurrentVoltage", e.g.

foreach (var item in new ManagementObjectSearcher("Select * from Win32_Processor").Get())
{
    labelName.Content = (decimal.Parse(item["CurrentVoltage"].ToString()) / 10).ToString() + " v";
}

As you can see in the image, it's reading as 0v in the picture. I was wondering if I would need to switch "CurrentVoltage" to "VoltageCaps", or if I would need to do something like reading the SMBIOS directly.

If the latter, please specify how to do so, thanks.

回答1:

Based on the documentation for the Win32_Processor class:

Voltage of the processor. If the eighth bit is set, bits 0-6 contain the voltage multiplied by 10. If the eighth bit is not set, then the bit setting in VoltageCaps represents the voltage value. CurrentVoltage is only set when SMBIOS designates a voltage value.

This means that if it reads as 0 when masked with 0x80, then you should use the value from VoltageCaps to 'state' the voltage as one of the 3 listed values for VoltageCaps, unless the result of querying is NULL, in which case the voltage is unknown.



标签: c# wmi