@echo off
:: Use WMI to retrieve battery status information
FOR /F "tokens=1* delims==" %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryStatus Get Charging^,Critical^,Discharging /Format:list ^| FIND "=TRUE"') DO ECHO Battery is %%A
FOR /F "tokens=* delims=" %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryStatus Get PowerOnline^,RemainingCapacity /Format:list ^| FIND "="') DO SET Battery.%%A
FOR /F "tokens=* delims=" %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryRuntime Get EstimatedRuntime /Format:list ^| FIND "="') DO SET Battery.%%A
FOR /F "tokens=* delims=" %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryFullChargedCapacity Get FullChargedCapacity /Format:list ^| FIND "="') DO SET Battery.%%A
:: Calculate runtime left and capacity
SET /A Battery.EstimatedRuntime = ( %Battery.EstimatedRuntime% + 30 ) / 60
SET /A Battery.RemainingCapacity = ( %Battery.RemainingCapacity%00 + %Battery.FullChargedCapacity% / 2 ) / %Battery.FullChargedCapacity%
:: Display results
echo.
echo.
IF /I "%Battery.PowerOnline%"=="TRUE" (
ECHO Now working on main power
ECHO.
ECHO Battery %Battery.RemainingCapacity%%% charged
ECHO.
ECHO.
) ELSE (
ECHO.
ECHO Estimated remaining runtime %Battery.EstimatedRuntime% minutes
ECHO.
ECHO Remaining capacity %Battery.RemainingCapacity%%%
ECHO.
ECHO.
)
pause
GOTO:EOF