WMI Battery Status - Batch file



Nothing much really, but this batch file uses WMI to list battery status. Zipped batch file attached.

Code:
@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


Output -

WMIBatterystatus.PNG


Enjoy the rest of your weekend!

John

 

Attachments

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top