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