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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24004300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:36:10  来源:igfitidea点击:

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

windowsbatch-filewindows-7cputemp

提问by 09stephenb

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.

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

回答by Kevin Richardson

You can use wmic.exe:

您可以使用wmic.exe

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

The output from wmiclooks like this:

的输出wmic如下所示:

CurrentTemperature
2815

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

的单位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%

A few things:

一些东西:

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

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

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

2) 每个引导周期该值可能会或可能不会更新超过一次。

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

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

回答by David Ruhmann

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

回答by SachaDee

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.

这将输出开尔文度数的温度。