How can I check if computer is plugged into AC power in a batch file in windows 7, like on_ac_power
does in linux?
Here is the script I am using in our environnement, works nicely:
wmic path Win32_Battery Get BatteryStatus | find /v "BatteryStatus" | find "1" >nul 2>&1
if "%errorlevel%" == "0" (echo Do whatever you want if on BATTERY) else (echo Do whatever you want if on AC POWER)
Description:
From the wmic command, isolate the number from the output.
Try to find the number "1" in the result. If succesfull, it means the computer is running on battery only. The official terminology is "(1) The battery is discharging."
Else, the computer is plugged in AC power.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With