-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaptopBatteryNotifier.vbs
50 lines (39 loc) · 2.03 KB
/
LaptopBatteryNotifier.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
' Lithium Ion Battery Life Tips:
' https://www.howtogeek.com/169669/debunking-battery-life-myths-for-mobile-phones-tablets-and-laptops/
' https://batteryuniversity.com/index.php/learn/article/how_to_prolong_lithium_based_batteries
' complete VBS script source: https://thegeekpage.com/battery-full-charged-notification-in-windows-10/
set locator = CreateObject("WbemScripting.SWbemLocator")
set wmiServices = locator.ConnectServer(".","root\wmi")
set capacityResults = wmiServices.ExecQuery("select * from batteryfullchargedcapacity")
fullCapacity = 0
for each capacityResult in capacityResults
fullCapacity = fullCapacity + capacityResult.FullChargedCapacity
next
' Source of "vbExclamation" :
' https://devblogs.microsoft.com/scripting/how-can-i-play-a-sound-each-time-a-message-box-is-displayed/
' Source of else if statement's syntax:
' https://www.promotic.eu/en/pmdoc/ScriptLangs/VBScript/Statmn/IfThenElse.htm
while (1)
set capacityResults = wmiServices.ExecQuery("select * from batterystatus")
' accessing 1st battery.
' source: https://stackoverflow.com/a/2378839
' remaining = capacityResults.ItemIndex(0).RemainingCapacity
' isCharging = capacityResults.ItemIndex(0).Charging
isCharging = 0
remaining = 0
for each capacityResult in capacityResults
remaining = remaining + capacityResult.RemainingCapacity
If (capacityResult.Charging) Then
isCharging = capacityResult.Charging
End If
next
batteryPercentage = Round((remaining / fullCapacity) * 100)
If (isCharging) and (batteryPercentage > 95) Then
msgbox "Laptop "& batteryPercentage &"% charged. Remove Charger !", vbExclamation, "Warning!"
ElseIf (batteryPercentage = 100) Then
msgbox "Laptop "& batteryPercentage &"% charged."& vbNewLine &"Please ignore if you have already removed the charger.", vbExclamation, "Warning!"
ElseIf (not isCharging) and (batteryPercentage < 20) Then
msgbox batteryPercentage &"% battery remaining. Please charge !", vbExclamation, "Warning!"
End If
wscript.sleep 1000*60*5 ' 5 minutes (in miliseconds)
wend