Batch-file get CPU temperature in °C and set as variable

安稳与你 提交于 2019-12-03 06:59:05

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
Kevin Richardson

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!