Get CPU Temperature Get CPU Temperature windows windows

Get CPU Temperature


The link to source for OpenHardwareMonitorLib provided in Tomer's answer illustrates what has to happen at a low level to read this information out of different types of CPUs. For example, the IntelCPU class defines some model-specific registers:

private const uint IA32_THERM_STATUS_MSR = 0x019C;private const uint IA32_TEMPERATURE_TARGET = 0x01A2;private const uint IA32_PERF_STATUS = 0x0198;private const uint MSR_PLATFORM_INFO = 0xCE;private const uint IA32_PACKAGE_THERM_STATUS = 0x1B1;private const uint MSR_RAPL_POWER_UNIT = 0x606;private const uint MSR_PKG_ENERY_STATUS = 0x611;private const uint MSR_DRAM_ENERGY_STATUS = 0x619;private const uint MSR_PP0_ENERY_STATUS = 0x639;private const uint MSR_PP1_ENERY_STATUS = 0x641;

These are straight out of Intel's docs like CPU Monitoring with DTS/PECI (section 16 "Direct MSR Access"). They may also be documented in the Intel Software Developer Manual but I haven't checked.

The OpenHardwareMonitorLib uses Rdmsr and RdmsrTx to get temperature values out of the MSRs of interest.

The corresponding AMD code looks like it gets similar info out of a PCI register. AMD will have equivalent documentation somewhere that will define this.

In both cases these are, by definition, how the hardware exposes information about its temperature sensors. You can use a library like this and it'll be doing this under the hood, or you can write equivalent code of your own.


Truth to be told, it depends on the hardware.

A library that works on most hardware is OpenHardwareMonitorLib. Unfortunately, it has no documentation and actually doesn't really exist as an independent piece of software. It's part of an open source software named "Open Hardware Monitor". it's done in .NET C Sharp and of course, only works for Windows. Fortunately you can get it as a DLL, and the GUI is completely separated from the actual backend which is OpenHardwareMonitorLib.

Read this post on how to use it from C++

How to call a C# library from Native C++ (using C++\CLI and IJW)

So considering it has no docs this can be a bit hard to work with. After reading the source for a while this is my take:

using OpenHardwareMonitor.Hardware;...        float? cpu_temperature_celcius = null;        Computer computer= new Computer();        computer.CPUEnabled = true;        computer.Open();        foreach (IHardware hardware in computer.Hardware)            if (hardware.HardwareType == HardwareType.CPU)                foreach (ISensor sensor in hardware.Sensors)                    if (sensor.SensorType == SensorType.Temperature)                        cpu_temperature_celcius = sensor.Value;

This #C code is confirmed to get the temperature of an Intel Haswell CPU in Celcius successfully. It will most likely work for most other CPUs from AMD and Intel. OpenHardwareMonitorLib.dll is needed. You can compile it from source

You can get a lot of other information about the system with this library.

Note that the CPU of the user can have multiple temperature sensors. For example a temperature sensor for every core, so don’t always take the last one as I did in the example above.

Good luck.


The mentioned WMI classes were not working for me in latest Windows 10.On my Dell-Laptop I could get the CPU-Temperature in Celsius here:

ROOT_CIMV2\Win32_PerfFormattedData_Counters_ThermalZoneInformation\HighPrecisionTemperature