我从网上找到了一些警告指示器的代码。我用它来警告我,当电池充电和电池水平高于80%。
但我也想用它来警告我,当电池电量低于20%。我已经为这个20%的警告添加了一行,但它不起作用。当电池电量超过80%时工作,但当电池电量低于20%时不工作。
我认为代码是在Visual Basic脚本(VBS)。
请帮帮我
我已经在其他论坛和这个论坛上搜索过了,但是在任何地方都找不到这样的程序。
set oLocator = CreateObject("WbemScripting.SWbemLocator")
set oServices = oLocator.ConnectServer(".","root\wmi")
set oResults = oServices.ExecQuery("select * from batteryfullchargedcapacity")
for each oResult in oResults
iFull = oResult.FullChargedCapacity
next
while (1)
set oResults = oServices.ExecQuery("select * from batterystatus")
for each oResult in oResults
iRemaining = oResult.RemainingCapacity
bCharging = oResult.Charging
next
iPercent = ((iRemaining / iFull) * 100) mod 100
if bCharging and (iPercent > 80) Then msgbox "Battery is charged now more than 80%. Please stop charging for optimal battery life."
if bCharging and (iPercent < 20) Then msgbox "Battery is discharging and is below 20%. Please switch on charging immediately."
wscript.sleep 30000 ' 5 minutes
wend
2条答案
按热度按时间i1icjdpr1#
如果您需要一台笔记本电脑监控2个或更多电池:
kkbh8khc2#
将-
if bCharging and (iPercent < 20)
更改为if iRemaining and (iPercent < 20)
,因为b充电是在插入时,而iRemaining是在使用电池时