12

How do i get a batch-file to work out the temperature of the Cpu and return it as a variable. I know it can be done as i have seen it been done. The solution can use any external tool. I have looked on Google for at least 2 hours but found nothing. Can any one help. Thanks.

3 Answers 3

16

You can use wmic.exe:

wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature

The output from wmic looks like this:

CurrentTemperature
2815

The units for MSAcpi_ThermalZoneTemperature are tenths of degrees Kelvin, so if you want celsius, you'd do something like this:

@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%

A few things:

1) The property may or may not be supported by your hardware.

2) The value may or may not update more than once per boot cycle.

3) You may need Administrative privileges to query the value.

3
  • 2
    When I run this I get 2982, which is 298.2 Kelvin 298.2-273=25.2 degrees C. This is 77 degrees F which is way cooler than my CPU temp. I'm pretty sure this is just giving me the room temperature not the cpu temperature.
    – Eric
    Aug 15, 2016 at 15:37
  • I ran this and got the same 2815, which is 8.35c. That can't be right! Nov 14, 2016 at 9:11
  • This is hardware-dependent and may or may not be accurate, but it's the best you can do from a batch file and built-in facilities. Feb 17, 2017 at 21:17
14

Here is an example which keeps the decimal values and uses the full conversion value.

Code

@echo off
for /f "skip=1 tokens=2 delims==" %%A in ('wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value') do set /a "HunDegCel=(%%~A*10)-27315"
echo %HunDegCel:~0,-2%.%HunDegCel:~-2% Degrees Celsius

Output

38.05 Degrees Celsius
5
  • 1
    Just adding here that not all hardware supports the query.
    – foxidrive
    Jun 3, 2014 at 1:02
  • @foxidrive Yep, that and the other items that Kevin lists in his answer are true. Jun 3, 2014 at 1:04
  • 1
    +1 for better attention to detail in the batch code. Jun 3, 2014 at 1:31
  • 1
    Thanks it works. May i ask waht is the update speed is.
    – 09stephenb
    Jun 3, 2014 at 12:24
  • 1
    It returns 2992 on my notebook, that is, 26.05 degrees Celsius, while some monitoring software shows 67.6 degrees Celsius, which is more likely since CPU is busy right now. May 17, 2016 at 14:29
2

If you computer support it you can try like this :

 wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature

This will output the temperature in degree Kelvin.

1
  • It actually returns tenths of degrees Kelvin. Also, the main/important part of his question is actually getting the output into a batch script variable, which isn't straightforward. Some likely ugly combination of FOR, SET, and FINDSTR will be needed. Jun 2, 2014 at 23:04

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.