Problem when trying to get CPU temperature using WMIC

Asked

Viewed 122 times

0

I’m creating a program for Windows and need to get the user’s CPU temperature. For this task I am using the wmic with the following code in batch:

@echo off

for /f "delims== tokens=2" %%a in (
    'wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value'
) do (
    set /a degrees_celsius=%%a / 10 - 273
)

echo %degrees_celsius% GRAUS
pause

The problem is that the temperature shown is always 64 GRAUS and the original return of wmic is the temperature in Kelvin of 3372. I did several tests to confirm whether this temperature was correct or not. I turned off the computer and waited a while for the CPU to cool, opened temperature measurement programs, and the result of that program in batch was always the same.

I’m doing something wrong, it’s some problem in the wmic or the lack of any resource on my computer ?

  • Just strengthening, here also the value is not changing, Windows 10. I put the CPU for stress test and the value does not change.

  • Why not pull directly from the Windows API by writing some application? I have a temperature reading application via API and works well in all versions above Windows 7.

  • The program I am creating is in Python. I searched the Windows API documentation for "pywin32" but there is nothing there related to temperature. Before anyone speaks, libraries that have temperature measurement functions for Python do not work on my computer (I tested all libraries I found on the internet).

1 answer

0

I managed to do on Windows 8.1, but when I went to try the same batch on Windows 10 it didn’t work (I tried to run it on Windows 10 by remote connection because I don’t have access to a real Windows at the moment.

@echo off
Title Mostrando a temperatura da CPU
:start
for /f "skip=1 delims=" %%a in ('"wmic path Win32_PerfRawData_Counters_ThermalZoneInformation get temperature"') do set /a Temperatura_Kelvin=%%a& goto Calculos

:Calculos
set /a Temperatura_Celcius=(%Temperatura_Kelvin%*100)-27315
set /a inteiros=%Temperatura_Celcius:~0,-2%
set /a quebrados=%Temperatura_Celcius:~-2%
set Temperatura_Celcius=%inteiros%,%quebrados%
set /a Temperatura_Fahrenheit=(%Temperatura_Kelvin% * 100 - 27315) * 9 
set /a Sobra_Fahrenheit=%Temperatura_Fahrenheit% %% 5
set /a Temperatura_Fahrenheit=%Temperatura_Fahrenheit% / 5
set /a inteiros=%Temperatura_Fahrenheit:~0,-2% + 32
set /a quebrados=%Temperatura_Fahrenheit:~-2% + %Sobra_Fahrenheit%
set Temperatura_Fahrenheit=%inteiros%,%quebrados%
cls
echo.
echo.
echo   Temperatura da CPU: %Temperatura_Celcius%ø Celcius ^| %Temperatura_Kelvin% Kelvin ^| %Temperatura_Fahrenheit%ø Fahrenheit
echo.
timeout /t 1 > Nul
goto :start

inserir a descrição da imagem aqui

For some reason whenever you use the formula to convert Kelvin to Celcius (Kelvin - 273.15 = Celcius) always remains a rest of 85 or 15....

  • I tried this code and this time at least it showed something different, but it is still not the right one. The output is being this: "CPU temperature: -1,-2° Celcius | Kelvin | 32,64° Fahrenheit".

  • And which Windows you use because in my Windows 10 happened something like this too.

  • I use Windows 7

Browser other questions tagged

You are not signed in. Login or sign up in order to post.