I got some code from the internet for a warning indicator. I use it for warning me when battery is charging and the battery level is above 80%.
But I also want to use it to warn me when the battery level is below 20%. I have added a line for this 20% warning, but it is not working. It works when battery is above 80%, but not when battery is below 20%.
I think the code is in Visual Basic Script (VBS).
Please help.
I have already searched on other forums and this one, but could not find such a program anywhere.
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
To add the battery icon to the taskbar: Select Start > Settings > Personalization > Taskbar, and then scroll down to the notification area. Choose Select which icons appear on the taskbar, and then turn on the Power toggle.
Expand the Battery menu. Expand the Low battery notification menu. To enable the low battery notification, set it to On for On battery and Plugged in. Click Apply > OK to save the changes.
Just tap on the CHARGE ALARM to get things done. After that, it will notify you whenever your battery charging will reach 100%. You can also change the default alarm tone and tweak other things. For that, just go to Settings and check corresponding options.
If you need one that monitors 2 or more batteries in one laptop:
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")
totalRemaining = 0
batteryCount = 0
for each oResult in oResults
iRemaining = oResult.RemainingCapacity
bCharging = oResult.Charging
totalRemaining = totalRemaining + iRemaining
batteryCount = batteryCount + 1
next
iPercent = Round(((totalRemaining / batteryCount) / iFull) * 100)
if bCharging and (iPercent > 80) Then msgbox "Battery is charged now more than 80%. Please stop charging for optimal battery life."
if not bCharging and (iPercent < 20) Then msgbox "Battery is discharging and is below 20%. Please switch on charging immediately."
wscript.sleep 3000000 ' sleep for 5 minutes
wend
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With