Guide | How To VBScript to get an alert when battery is charged - Windows

The associated guide may contain user-generated or external content.

KaptainBug

Level 12
Thread author
Verified
Dec 26, 2013
562
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 > 95) Then msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
wscript.sleep 300000 ' 5 minutes
wend
Please note, I have changed 30000 to 300000 in the above script, which corresponds to 5 minutes.
Its also advisable, to change iPercent > 95 to iPercent > 90, because the script does not alert you when battery is fully charged, i.e., at 100%. So if the charging rate from 95-100% is less than 5 minutes, you will never get an alert. For this reason, I recommend to change the level to 90%.

Save the above script as .vbs extension and make a startup entry in Windows.

Source:
http://blogs.technet.com/b/jhoward/archive/2013/04/24/get-an-alert-when-my-battery-reaches-95.aspx

http://www.addictivetips.com/windows-tips/get-alerts-when-your-laptop-battery-is-low-or-full/
 
  • Like
Reactions: Oxygen

Bharat(bb)

New Member
Jan 15, 2015
3
can u tell me the command for low battery same like "FullChargedCapacity" i want to write a script for low battery.......:D
 

KaptainBug

Level 12
Thread author
Verified
Dec 26, 2013
562
can u tell me the command for low battery same like "FullChargedCapacity" i want to write a script for low battery.......:D
You don't need one for low battery as Windows will itself notify in such a case. You can change the low battery level by going to power options under control panel and change the low battery percentage.
 

Bharat(bb)

New Member
Jan 15, 2015
3
when i watching movie the error show in background that's why some times i dint get the alert there is any method for show error in foreground....?
 

KaptainBug

Level 12
Thread author
Verified
Dec 26, 2013
562
when i watching movie the error show in background that's why some times i dint get the alert there is any method for show error in foreground....?
When I used the script, message prompt always appear in foreground even when watching youtube videos on fullscreen. Don't know why it does not in your case.
I can prepare a script if you would like, that will play a notification sound along with the message prompt. So even if you miss the prompt you can get notified by the sound.
 

pcuser88

Level 1
Sep 15, 2016
9
When I used the script, message prompt always appear in foreground even when watching youtube videos on fullscreen. Don't know why it does not in your case.
I can prepare a script if you would like, that will play a notification sound along with the message prompt. So even if you miss the prompt you can get notified by the sound.

Don't know if this will still reach you from 2018. Please add a notification sound to the script.
 

About us

  • MalwareTips is a community-driven platform providing the latest information and resources on malware and cyber threats. Our team of experienced professionals and passionate volunteers work to keep the internet safe and secure. We provide accurate, up-to-date information and strive to build a strong and supportive community dedicated to cybersecurity.

User Menu

Follow us

Follow us on Facebook or Twitter to know first about the latest cybersecurity incidents and malware threats.

Top