已知:powercfg /batteryreport 可以查看系统电池信息,
问题:需要在改变充电状态大约5.6秒过后才能刷新出最新状态
目的:有其他方法可以查看,或者及时刷新充电状态的命令吗
以下自己琢磨的,谢谢各位指点- @ECHO OFF
- del battery-report.html>nul 2>nul
- del battery.ini>nul 2>nul
- del n.ini>nul 2>nul
-
- powercfg /batteryreport
- setlocal EnableDelayedExpansion
- cd /d %~dp0
- set n=0
- For /f "tokens=1* delims=:" %%i in ('Type battery-report.html^|Findstr /n /c:"Report generated"') do (
- Set /a n=%%i+1
- ECHO !n!>>n.ini
- )
- endlocal
-
- set /p number=<n.ini
- set /a numa=%number%-1
- set /a numb=%number%+2
- call :checknum %numa% %numb%
- findstr "Battery" battery.ini &&echo fail>result.log||echo pass>result.log
- exit
-
- :checknum
- setlocal enabledelayedexpansion
- for /l %%m in (%1,1,%2) do (
- set lineFlag=0
- for /f "delims=" %%r in ('type battery-report.html') do (
- set /a lineFlag+=1
- if !lineFlag!==%%m (
- set lineContent=%%r
- set lineContent=!lineContent: =!
- echo.!lineContent!>>battery.ini
- )
- )
- )
- endlocal
- goto :eof
复制代码 找到方案了:
wmic path Win32_Battery Get BatteryStatus |