0
所以,我只是想知道如何获得批量电池的百分比。
我认为这将是一件好事,如果格式是这样的:如何获得批量电池的百分比?
:forever
get-battery
if "%battery%"=="100%" goto reached100
goto forever
:reached100
echo Your battery has finished charging!
goto forever
所以,我只是想知道如何获得批量电池的百分比。
我认为这将是一件好事,如果格式是这样的:如何获得批量电池的百分比?
:forever
get-battery
if "%battery%"=="100%" goto reached100
goto forever
:reached100
echo Your battery has finished charging!
goto forever
使用WMIC
:: Variables to translate the returned BatteryStatus integer to a descriptive text
SET BatteryStatus.1=discharging
SET BatteryStatus.2=The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.
SET BatteryStatus.3=fully charged
SET BatteryStatus.4=low
SET BatteryStatus.5=critical
SET BatteryStatus.6=charging
SET BatteryStatus.7=charging and high
SET BatteryStatus.8=charging and low
SET BatteryStatus.9=charging and critical
SET BatteryStatus.10=UNDEFINED
SET BatteryStatus.11=partially charged
:: Read the battery status
FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Battery Get BatteryStatus /Format:List ^| FIND "="') DO SET %%A
:: Check the battery status, and display a warning message if running on battery power
IF NOT "%BatteryStatus%"=="2" (
> "%~dpn0.vbs" ECHO MsgBox vbLf ^& "The laptop is currently running on its battery." ^& vbLf ^& vbLf ^& "The battery is !BatteryStatus.%BatteryStatus%!." ^& vbLf ^& vbLf ^& "Connect the laptop to the mains voltage if possible." ^& vbLf ^& " "^, vbWarning^, "Battery Warning"
CSCRIPT //NoLogo "%~dpn0.vbs"
DEL "%~dpn0.vbs"
)
完整的剧本我永远无法理解为什么人们喜欢写[数组在批处理文件](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990)在一个不寻常的方式,这给了他们一个奇怪的和神秘的外观,经常需要解释,我除了使用世界上常用的方形布拉克斯标准方式:'SET BatteryStatus [1] =放电';请参阅:[this comment](http://stackoverflow.com/questions/10544646/dir-output-into-bat-array/10569981#10569981)。 – Aacini 2014-11-07 05:44:14
我想要百分比。比如:'100'(100%)或'2'(2%),所以我可以在“IF”命令中使用它。 – 2014-11-08 04:06:44
而不是'BatteryStatus',尝试'EstimatedChargeRemaining' – RealHowTo 2014-11-08 14:41:30