繁体   English   中英

批处理文件以°C为单位获取CPU温度并设置为变量

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

如何获取批处理文件以计算出Cpu的温度并将其作为变量返回。 我知道它可以完成,因为我已经看到它已经完成。 该解决方案可以使用任何外部工具。 我在谷歌上看了至少2个小时,但一无所获。 任何人都可以帮忙。 谢谢。

你可以使用wmic.exe

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

wmic的输出如下所示:

CurrentTemperature
2815

MSAcpi_ThermalZoneTemperature的单位是开尔文的十分之一,所以如果你想要摄氏度,你会做这样的事情:

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

一些东西:

1)您的硬件可能支持或不支持该属性。

2)每个引导周期可以更新或不更新一次。

3)您可能需要管理权限才能查询该值。

下面是一个保留十进制值并使用完整转换值的示例。

@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

产量

38.05 Degrees Celsius

如果您的计算机支持它,您可以尝试这样:

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

这将以开尔文度输出温度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM