Battery Alarm VBS Script

Simple VBS script (save it as .vbs file and run) to get once the laptop battery is charged up to given (90 in this case) percentage.

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 > 90) Then msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
 wscript.sleep 30000 ' 5 minutes
wend
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s