A windows 10 battery charging level script in startup.


  1. Posts : 69
    win10 pro
       #1

    A windows 10 battery charging level script in startup.


    I'm not sure were to post this in the forum, so I posted here.
    I came across a windows script that runs at startup and displays a battery (no)charging level every few minutes.
    The original microsoft script has a bug in it, but I'm looking for the weblink again that I misplaced. It originally
    polled the battery via the startup every few minutes and told one when it hit 95%. However, in my case, I've modified
    it to tell me the following when the adapter is plugged in,
    a). whether it is charging and at what percentage it is stuck at - only once - and then stops displaying. to minimize annoying popups.
    b). whether it is fully charged only once.
    c). what the current charge percentage is every 5 minutes (this time delay can be changed in the script).

    It doesn't display the battery % as it discharges without the adapter plugin, but the script can be modified for this purpose.

    If the vbs script is disabled on reboot, then it does nothing.
    The user can enable/disable the script per the task manager "startup" tab by right clicking on the program to enable/disable it upon the next reboot of the computer, or just kill the task or delete it from startup.

    The BatteryStatus.vbs script is pasted to this directory and is activated on reboot.
    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
    Code:
    set oLocator = CreateObject("WbemScripting.SWbemLocator")
    set oServices = oLocator.ConnectServer(".","root\wmi")
    set oResults = oServices.ExecQuery("select * from batteryfullchargedcapacity")
    
    for each oResult in oResults
    isFull = oResult.FullChargedCapacity
    msgbox "Battery isFull is at " & isFull, vbInformation, "Battery monitor"
    next
    
    Dim iShow
    iShow=1
    
    while (1)
    
    
    set oResults = oServices.ExecQuery("select * from batterystatus")
    for each oResult in oResults
    	isRemaining = oResult.RemainingCapacity  ' This is the value less than isFull.
    If (iShow = 1) Then ' Display only when things are charging, or only for first non charge event.
    msgbox "Battery isRemaining is at " & isRemaining, vbInformation, "Battery monitor"
    End If
    	bCharging = oResult.Charging
    next
    
    REM iPercent = ((isRemaining / isFull) * 100) mod 100 ' This gives computes to 0% when fully charged.
    iPercent = (isRemaining / isFull) *100 ' This is a more accurate value for percentage.
    
    
    If not bCharging and (iShow = 1) Then ' Check and display not charging once, until next charging state
    msgbox "Battery not charging and is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 0
    ElseIf bCharging and (iPercent < 10) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 10) or (iPercent < 20)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 20) or(iPercent < 30)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 30) or (iPercent < 40)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 40) or (iPercent < 50)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 50) or (iPercent < 60)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 60) or (iPercent < 70)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 70) or (iPercent < 80)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 80) or (iPercent < 90)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and ((iPercent = 90) or (iPercent < 100)) Then 
    msgbox "Battery is at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 1
    ElseIf bCharging and (iPercent = 100) and (iShow = 1) Then  ' Display that the battery is fully charged once, until it starts draining.
    msgbox "Battery is Fully Charged at " & iPercent & "%",vbInformation, "Battery monitor"
    iShow = 0
    End If 
    
    
    
    wscript.sleep 5*60*1000 ' 5 minutes  in 1msec increments.
    wend
    Last edited by swegmike; 04 Jan 2024 at 14:38.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:27.
Find Us




Windows 10 Forums