C++ code for CPU load and CPU temperature
Asked Answered
T

3

13

I want to see CPU temperature and CPU load in Windows. I have to write it myself not using software like Core Temp. How can I access this information?

I read a similar question to mine, but there was no useful answer:(.

Twum answered 7/11, 2011 at 4:43 Comment(0)
M
5

Recently I have started a similar project. I needed to read the cpu temperature and to control the fan in Linux and Windows. I don't know much about C++ and VS and DDK but I figured how to write a simple kernel driver and a simple program with winring0. In my laptop (and most other) the temperature and the fan is controled by the embedded controller. You have 2 choices, either you can write a kernel driver or you can use a library to access the embedded controller. It's because Windows protect the ec from being accessed with normal user rights. A good (and working) library is winring0 (WinRing0_1_3_1b). A useful program to check the ec and everything else in Windows is the RW tool.

Masterstroke answered 7/11, 2011 at 5:2 Comment(4)
Thanks Jitamaro. I actually looking for a simple code to see what win32 API should be used.Twum
Its inp() and outp() function from some windows header to read and write to the ec. You need to find the correct register but there can be other ways, too.Masterstroke
What's the output of a program like that? Is it like an integer in Celcious or Fahrenheit? Is it possible to write a command line program that outputs microtemperature of a CPU? It would be nice for a seed in a random number generator in my PHP script.Salto
Temps are in bytes and it depends what os you are using. In Linux there is the acer_ec.pl script. In windows you must write a driver or use an api because the ec isn't exposed.Masterstroke
D
1

Take a look at Getting CPU temp from MSDN forums, there are a few approaches.

As to the sane way, you can use Win32_TemperatureProbe class, that gets its intel from SMBIOS.

Developer answered 7/11, 2011 at 5:13 Comment(1)
The linked content on Win32_TemperatureProbe says "the CurrentReading property cannot be extracted". It tells you about the temperature probe, not its value.Skelton
M
0

In all the forums and posts I have read I have not seen a successful implementation using WMI. Someone claims it works then someone else says I got error xyz which means it doesn’t work for all processors and motherboard. I have not succeeded either.

With OpenHardware Monitor it works but in my implementations it only provides CPU temp and not Thread Temps and it is very slow compared with my preferred implementation which is Core Temp. The drawback is that Core Temp is an app which has to be running before temp data can be extracted and I am not aware of a straight DLL alternative. But it is fast and provides all Thread Temps on all platforms.

Mariammarian answered 1/6, 2023 at 23:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.