Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the CPU temperature?

Tags:

c#

.net

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 

or

MSAcpi_ThermalZoneTemperature 

How can I do this? I'm wondering how monitoring programs, as SiSoftware Sandra, can get that information...

Here is the code of the class:

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;     } } 
like image 715
yeyeyerman Avatar asked Jul 28 '09 16:07

yeyeyerman


People also ask

How do I check the temp of my CPU?

Checking your CPU temperature is as easy as installing and using monitoring software and then reading the value. There are multiple programs to choose from, with the best tools for checking CPU temperature, including Core Temp (opens in new tab), NZXT's CAM (opens in new tab), AIDA64, HWiINFO, or HWMonitor.

Can you check CPU temp Windows 10?

There is no such option to check CPU temperature in Windows 10. You can either check the temperature in BIOS or you can use third-party applications.


1 Answers

For others who may come by here, maybe take a look at : http://openhardwaremonitor.org/

Follow that link and at first you might think, "Hey, that's an application, and that is why it was removed. The question was how to do this from C# code, not to find an application that can tell me the temperature..." This is where it shows you are not willing to invest enough time in reading what "Open Hardware Monitor" also is.

They also include a data interface. Here is the description:

Data Interface The Open Hardware Monitor publishes all sensor data to WMI (Windows Management Instrumentation). This allows other applications to read and use the sensor information as well. A preliminary documentation of the interface can be found here (click).

When you download it, it contains the OpenHardwareMonitor.exe application, and you're not looking for that one. It also contains the OpenHardwareMonitorLib.dll, and you're looking for that one.

It is mostly, if not 100%, just a wrapper around the WinRing0 API, which you could choose to wrap yourself if you feel like it.

I have tried this out from a C# application myself, and it works. Although it was still in beta, it seemed rather stable. It is also open source, so it could be a good starting point instead.

like image 114
Jens Avatar answered Sep 22 '22 04:09

Jens