有没有办法区分笔记本电脑上的交流电和电池电源,以便在 Win 7 任务计划程序中使用?
答案1
@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.
上面的批处理文件使用Win32_电池WMI 类用于获取电池状态。扩展它以执行所需的操作,然后使用任务计划程序在需要时运行它。