如何获得CPU温度? [英] How can I get the CPU temperature?
问题描述
我需要为我正在开发的应用程序收集一些系统信息.可用内存和 CPU 负载很容易使用 C# 获得.不幸的是,CPU 温度并不是那么容易.我曾尝试使用 WMI,但我无法使用
I need to gather some system information for the application I'm developing. The memory available and the CPU load are easy to get using C#. Unfortunately, the CPU temperature it's not that easy. I have tried using WMI, but I couldn't get anything using
Win32_TemperatureProbe
或
MSAcpi_ThermalZoneTemperature
我该怎么做?我想知道作为 SiSoftware Sandra 的监控程序如何获取这些信息...
How can I do this? I'm wondering how monitoring programs, as SiSoftware Sandra, can get that information...
这里是类的代码:
public class SystemInformation
{
private System.Diagnostics.PerformanceCounter m_memoryCounter;
private System.Diagnostics.PerformanceCounter m_CPUCounter;
public SystemInformation()
{
m_memoryCounter = new System.Diagnostics.PerformanceCounter();
m_memoryCounter.CategoryName = "Memory";
m_memoryCounter.CounterName = "Available MBytes";
m_CPUCounter = new System.Diagnostics.PerformanceCounter();
m_CPUCounter.CategoryName = "Processor";
m_CPUCounter.CounterName = "% Processor Time";
m_CPUCounter.InstanceName = "_Total";
}
public float GetAvailableMemory()
{
return m_memoryCounter.NextValue();
}
public float GetCPULoad()
{
return m_CPUCounter.NextValue();
}
public float GetCPUTemperature()
{
//...
return 0;
}
}
推荐答案
我很确定这取决于制造商,因为它们将通过 I/O 端口访问.如果您尝试使用特定的电路板,请尝试查看手册和/或联系制造商.
I'm pretty sure it's manufacturer dependent, since they will be accessed through an I/O port. If you have a specific board you're trying to work with, try looking through the manuals and/or contacting the manufacturer.
如果您想对许多不同的主板执行此操作,我建议您联系 SiSoftware 之类的人员或准备阅读大量主板手册.
If you want to do this for a lot of different boards, I'd recommend contacting someone at something like SiSoftware or be prepared to read a lot of motherboard manuals.
另外要注意的是,并非所有电路板都有温度监视器.
As another note, not all boards have temperature monitors.
您也可能会遇到从内核获得特权访问的问题.
You also might run into problems getting privileged access from the kernel.
这篇关于如何获得CPU温度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!