本文介绍了我如何获得批量电池的百分比是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我只是想知道如何获得批量电池百分比。结果
我认为这将是一件好事,如果格式是这样的:
:永远
拿到电池
如果%电池%==100%转到reached100
转到永远:reached100
回声您的电池充电完毕!
转到永远
解决方案
使用WMIC
::变量返回的电池状态整数转换成一个描述性文本
SET BatteryStatus.1 =放电
SET BatteryStatus.2 =该系统能够访问交流因此没有电池正在放电。然而,电池并不一定充电。
SET BatteryStatus.3 =完全充电
SET BatteryStatus.4 =低
SET BatteryStatus.5 =至关重要
SET BatteryStatus.6 =充电
SET BatteryStatus.7 =充电和高
SET BatteryStatus.8 =充电及低
SET BatteryStatus.9 =充电和关键
SET BatteryStatus.10 =未定义
SET BatteryStatus.11 =部分充电::了解电池状态
FOR / F令牌= *%% A IN('WMIC路径Win32_Battery获取电池状态/格式:列表^ | FIND=)确实建立一个%%::检查电池状态,并显示一条警告消息,如果使用电池电源运行
如果不是%电池状态%==2(
> %〜dpn0.vbsECHO MSGBOX vbLf ^&安培; 笔记本电脑目前已经在其电池运行。 ^&安培; vbLf ^&安培; vbLf ^&安培; 电池是!电池状态%电池状态%! ^&安培; vbLf ^&安培; vbLf ^&安培; 连接笔记本电脑电源,如果可能的电压。 ^&安培; vbLf ^&安培; ^,^ vbWarning电池警告
CSCRIPT // NOLOGO%〜dpn0.vbs
DEL%〜dpn0.vbs
)
检查完整的脚本在
So, I just want to know how to get the battery percentage in Batch.
I think it would be good if the format was like this:
:forever
get-battery
if "%battery%"=="100%" goto reached100
goto forever
:reached100
echo Your battery has finished charging!
goto forever
解决方案
Using WMIC
:: Variables to translate the returned BatteryStatus integer to a descriptive text
SET BatteryStatus.1=discharging
SET BatteryStatus.2=The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.
SET BatteryStatus.3=fully charged
SET BatteryStatus.4=low
SET BatteryStatus.5=critical
SET BatteryStatus.6=charging
SET BatteryStatus.7=charging and high
SET BatteryStatus.8=charging and low
SET BatteryStatus.9=charging and critical
SET BatteryStatus.10=UNDEFINED
SET BatteryStatus.11=partially charged
:: Read the battery status
FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Battery Get BatteryStatus /Format:List ^| FIND "="') DO SET %%A
:: Check the battery status, and display a warning message if running on battery power
IF NOT "%BatteryStatus%"=="2" (
> "%~dpn0.vbs" ECHO MsgBox vbLf ^& "The laptop is currently running on its battery." ^& vbLf ^& vbLf ^& "The battery is !BatteryStatus.%BatteryStatus%!." ^& vbLf ^& vbLf ^& "Connect the laptop to the mains voltage if possible." ^& vbLf ^& " "^, vbWarning^, "Battery Warning"
CSCRIPT //NoLogo "%~dpn0.vbs"
DEL "%~dpn0.vbs"
)
Check the complete script at http://www.robvanderwoude.com/files/battrun_xp.txt
这篇关于我如何获得批量电池的百分比是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!