How to get CPU temperature?
How to get CPU temperature?
I need to gather some system's 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
Has anybody already dealt with this issue? I'm wondering how monitoring programs, as SiSoftware Sandra, can get that information...
Just in case anybody is interested, 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; } }
Answer by samoz for How to get CPU temperature?
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.
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.
Answer by Jon Grant for How to get CPU temperature?
There is a blog post with some C# sample code on how to do it here.
Answer by Lasse Rasch for How to get CPU temperature?
I know this post is old, but just wanted to add a comment if somebody should be looking at this post and trying to find a solution for this problem.
You can indeed read the CPU temperature very easily in C# by using a WMI approach.
To get a Celsius value, I have created a wrapper that converts the value returned by WMI and wraps it into an easy to use object.
Please remember to add a reference to the 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 Temperatures { get { List result = new List(); 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 25.06.2010:
(Just saw that a link was posted to the same kind of solution above... Anyway, I will leave this piece of code if somebody should want to use it :-) )
Answer by Jens for How to get CPU temperature?
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, 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, you're not looking for that one. It also contains the OpenHardwareMonitorLib.dll, 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 your self if you feel like it.
I have tried this out from a C# app myself, and it works. Although it is still in beta, it seemed rather stable. It is also open source so it could be a good starting point instead.
At the end of the day I find it hard to believe that is not on topic of this question.
Answer by Jet for How to get CPU temperature?
It can be done in your code via WMI. I've found a tool from Microsoft that creates code for it.
The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI.
You can download it here.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment