Skip to content

Instantly share code, notes, and snippets.

@xsnpdngv
Last active October 28, 2021 03:18
Show Gist options
  • Save xsnpdngv/0829df7a0d35f80c7cfeb9df81eb58f2 to your computer and use it in GitHub Desktop.
Save xsnpdngv/0829df7a0d35f80c7cfeb9df81eb58f2 to your computer and use it in GitHub Desktop.
battery full notification VB script
' Battery Full Notification VBS - checking in each 5 min
' To start automatically on logon, put into the directory that opens on:
' Win+R: Open: [shell:startup] -> [OK]
' (C:\Users\YOU\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)
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 > 97)
then msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
wscript.sleep 300000 ' 5 minutes
wend
@FazCodeFR
Copy link

Thanck !!

@nhandn139
Copy link

nhandn139 commented Mar 22, 2021

Could you add sound alarm code to that script? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment