How to get the temperature of the processor?

I need to collect some system information for the application that I am developing. Available memory and CPU utilization are easy to get with C #. Unfortunately, the temperature of the processor is not so simple. I tried using WMI, but I could not use anything with

Win32_TemperatureProbe 

or

 MSAcpi_ThermalZoneTemperature 

Has anyone already dealt with this problem? I am wondering how monitoring programs like SiSoftware Sandra can get this information ...

Just in case anyone is interested, here is the class code:

 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; } } 
+45
c # wmi
Jul 28 '09 at 16:03
source share
5 answers

I am sure it depends on the manufacturer, as they will be available through the I / O port. If you have a specific board that you are trying to work with, try looking through the manuals and / or contact the manufacturer.

If you want to do this for many different motherboards, I would recommend contacting someone for something like SiSoftware or be prepared to read a lot of motherboard manuals.

As another note, not all boards have temperature monitors.

You may also encounter problems getting privileged access from the kernel.

+18
Jul 28 '09 at 16:11
source share

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

Follow this link, and at first you might think: “Hey, this application, so it was deleted, the question was how to do this with C # code, and not to search for an application that can tell me the temperature ..” It shows that you don’t want to invest enough time in reading “Open Hardware Monitor”.

They also include a data interface, here is a description:

The Open Hardware Monitor data interface publishes all sensor data for WMI (Windows Management Tool). This allows other applications to read and use sensor information. preliminary documentation on the interface can be found here (click) .

When you download it, it contains the OpenHardwareMonitor.exe application, you are not looking for it. It also contains the OpenHardwareMonitorLib.dll file that you are looking for.

Basically, if not 100%, this is just a wrapper around the WinRing0 API, which you can choose to wrap yourself if you like.

I myself tried this from a C # application and it works. Although it is still in beta, it looks pretty stable. It is also open source, so it can be a good starting point.

At the end of the day, I find it hard to believe that this is not a question on this issue.

+44
Mar 05 '12 at 10:10
source share

I know this post is old, but just wanted to add a comment if someone should look at this post and try to find a solution to this problem.

You really can easily read the processor temperature in C # using the WMI approach.

To get the Celsius value, I created a wrapper that converts the value returned by WMI and transfers it to an easy-to-use object.

Be sure to add the link to System.Management.dll in Visual Studio.

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; namespace RCoding.Common.Diagnostics.SystemInfo { public class Temperature { public double CurrentValue { get; set; } public string InstanceName { get; set; } public static List<Temperature> Temperatures { get { List<Temperature> result = new List<Temperature>(); ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature"); foreach (ManagementObject obj in searcher.Get()) { Double temp = Convert.ToDouble(obj["CurrentTemperature"].ToString()); temp = (temp - 2732) / 10.0; result.Add(new Temperature { CurrentValue = temp, InstanceName = obj["InstanceName"].ToString() }); } return result; } } } } 

Update 06/25/2010:

(I just saw that the link was sent to the same solution above ... Anyway, I will leave this part of the code if someone wants to use it :-))

+30
Jun 24 2018-10-06T00:
source share

There is a blog post with some C # code example on how to do this here .

+3
Jul 28 '09 at 16:13
source share

This can be done in code through WMI. I found a tool from Microsoft that creates code for it.

The WMI code writer enables you to create VBScript, C #, and VB.NET code that uses WMI to perform management tasks, such as querying for management data, executing a method from the WMI class, or receiving event notifications using WMI.

You can download here .

+1
Mar 09 '13 at 8:41
source share



All Articles