Antworten:
@echo off
set bstat=
for /f "tokens=2 delims==" %%a in ('wmic path Win32_Battery get BatteryStatus /value ^| find "="') do set bstat=%%a
if [%bstat%]==[1] echo The battery is discharging.
if [%bstat%]==[2] echo The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.
if [%bstat%]==[3] echo Battery fully charged.
if [%bstat%]==[4] echo Battery low.
if [%bstat%]==[5] echo Battery critical.
if [%bstat%]==[6] echo Battery charging.
if [%bstat%]==[7] echo Battery charging and high.
if [%bstat%]==[8] echo Battery charging and low.
if [%bstat%]==[9] echo Battery charging and critical.
if [%bstat%]==[10] echo Battery status undefined.
if [%bstat%]==[11] echo Battery partially charged.
Die obige Batchdatei verwendet die WMI-Klasse Win32_Battery , um den Batteriestatus abzurufen . Erweitern Sie es, um die erforderlichen Aktionen auszuführen, und verwenden Sie dann den Taskplaner, um es bei Bedarf auszuführen.