如何批量获取电池百分比?

时间:2014-11-07 00:48:05

标签: windows batch-file cmd batterylevel

所以,我只是想知道如何批量获取电池百分比 我认为如果格式是这样的话会很好:

:forever
get-battery
if "%battery%"=="100%" goto reached100
goto forever

:reached100  
echo Your battery has finished charging!
goto forever

3 个答案:

答案 0 :(得分:2)

使用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://www.robvanderwoude.com/files/battrun_xp.txt

上的完整脚本

答案 1 :(得分:1)

scientist_7的答案应标记为正确。

当然,没有法律禁止批量调用Powershell。

powershell -command "(Get-WmiObject Win32_Battery).EstimatedChargeRemaining"
56

答案 2 :(得分:0)

您可以通过Wmic命令对其进行检查。

帮助链接= Wmic

这是我的方式=

@echo off
for /f "tokens=2 delims==" %%E in ('wmic path Win32_Battery get EstimatedChargeRemaining /value') do (set "Ba=%%E")
Echo Battery = %Ba%%%
pause>nul