I usually charge my laptop battery to 80% before disconnecting the charger so as to increase the battery life. The problem is that I often forget to check the battery level while charging and find out hours later that it’s been at 100%. I would like to create a task in Task Scheduler that displays a message when the battery level reaches 80%. But I don’t know how to add “battery level at x%” as a trigger for the task. I would appreciate your help very much.
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Create a task based on battery level
Home » Forums » AskWoody support » Windows » Windows 7 » Questions: Windows 7 » Create a task based on battery level
- This topic has 15 replies, 6 voices, and was last updated 11 years, 8 months ago.
AuthorTopicWSasifbaig
AskWoody LoungerMarch 3, 2013 at 5:37 am #488079Viewing 13 reply threadsAuthorReplies-
BATcher
AskWoody_MVPMarch 3, 2013 at 12:20 pm #1377931There’s no such Task Scheduler ‘trigger’, so you probably need to run a utility which will pop up a message when your required battery threshold is reached. I found Battery Status Tool, which may or may not do what you want.
The usual BatteryCare might perhaps assist, alternatively.
BATcher
Plethora means a lot to me. -
Paul T
AskWoody MVPMarch 3, 2013 at 12:22 pm #1377932If the battery is Lithium Ion there is no need to bother. These batteries have no discernible memory effect and full charge doesn’t reduce life.
If you still want to play I suggest you use WMI – built in to Windows – to check the current level. Download Scriptomatic to play with WMI.
cheers, Paul
-
WSasifbaig
AskWoody LoungerMarch 6, 2013 at 5:12 am #1378307I tried both of those tools but neither offer the required function.
I downloaded Scriptomatic 2.0 but it doesn’t run properly for some reason. It’s an html application and while it launches properly, it gives a “script error on this page, do you want to continue” error akin to the old days when I used to use Internet Explorer on an incompatible site (screenshot). I am running Windows 7 Home Premium and have Internet Explorer 9 (though I use Firefox as my browser). Because of this problem, most of the buttons are not usable (the drop down lists for example).
Is it because the Scriptomatic is outdated or that my Windows version (home premium) lacks some component?
-
Clive Pugh
MemberMarch 6, 2013 at 5:39 am #1378312I tried both of those tools but neither offer the required function.
I downloaded Scriptomatic 2.0 but it doesn’t run properly for some reason. It’s an html application and while it launches properly, it gives a “script error on this page, do you want to continue” error akin to the old days when I used to use Internet Explorer on an incompatible site (screenshot). I am running Windows 7 Home Premium and have Internet Explorer 9 (though I use Firefox as my browser). Because of this problem, most of the buttons are not usable (the drop down lists for example).
Is it because the Scriptomatic is outdated or that my Windows version (home premium) lacks some component?
I suspect that you need win 7 Pro minimum to get it to work as Home premium does not allow access to some of the hidden system settings. (GU-edit i think it may be called, maybe some one can correct this if incorrect as very likely).
-
-
WSjwitalka
AskWoody Lounger -
Paul T
AskWoody MVPMarch 6, 2013 at 1:25 pm #1378460Scriptomatic requires you to have admin credentials to run it. If you have UAC enabled you need to run it from an administrator Command Prompt.
Right click on “Command Prompt” and select “Run as administrator”.
Enter the full path to Scriptomatic, e.g. D:TempScriptomaticscriptomaticv2.htacheers, Paul
-
RetiredGeek
AskWoody_MVPMarch 6, 2013 at 2:04 pm #1378471asifbaig,
Here’s a possible solution. It may not be pretty but it does work.
Place the following PowerShell program in your default PowerShell Directory.Code:Param ( [Parameter (Mandatory=$False)] $BaseCapacity ) [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $MyBattery = Get-WmiObject -class BatteryStatus -ComputerName LocalHost -NameSpace rootWMI $BatteryRemaining = $MyBattery.RemainingCapacity/$BaseCapacity if(($BatteryRemaining -lt 0.87) -and $MyBattery.Discharging) { $Message = "Battery Low...Please Charge Me!" [Windows.Forms.MessageBox]::Show($Message, "Battery Status", ` [Windows.Forms.MessageBoxButtons]::OK , ` [Windows.Forms.MessageBoxIcon]::Information , ` [Windows.Forms.MessageBoxDefaultButton]::Button1, ` [Windows.Forms.MessageBoxOptions]::ServiceNotification) }
Note code also included in attachment.
Next create a scheduled task that will fire every hour (or time interval of your choice ).
33333-TSAction
Note: You need to pass to the program {after the program name in the Action pane of the scheduled task } the mWh ( milla Watt Hours ) FULL capacity of your battery! I used the Battery Meter program to find this value. So the optional parameters would look like d:pathBatteryStatus.ps1 7730Done!
When the task fires you will get the following message if the battery is below the threshold and you are NOT plugged in.
33332-LowBatteryMsg
See the messy part it shows a command window along with the message and that window will flash even if the message doesn’t display. When you click OK both windows close.The code as written checks for low battery since that was the easiest to check as I was writing the code. You can easily change the test from -le to -ge and also the percentage that follows to your desired threshold levels. You could also make the code check for both low & high charge conditions and print the appropriate message. BTW don’t forget to change the $Message value as appropriate.
HTH :cheers:
-
RetiredGeek
AskWoody_MVPMarch 7, 2013 at 3:59 pm #1378944Hey Y’all,
Here’s the latest version that kicks out messages for both Unplugged/Low Battery and Plugged in Charged Battery:
Code:Param ( [Parameter (Mandatory=$False)] $BaseCapacity ) [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $MyBattery = ` Get-WmiObject -class BatteryStatus -ComputerName LocalHost -NameSpace rootWMI $BatteryRemaining = $MyBattery.RemainingCapacity/$BaseCapacity $Message = "" if(($BatteryRemaining -lt 0.30) -and $MyBattery.Discharging) { $Message = "Battery Low...Please Charge Me!" } Elseif(($BatteryRemaining -gt 0.95) -and $MyBattery.PowerOnline) { $Message = "Battery CHARGED above 95%...Please Unplug Me!" } if($Message -ne "") { [Windows.Forms.MessageBox]::Show($Message, "Battery Status", ` [Windows.Forms.MessageBoxButtons]::OK , ` [Windows.Forms.MessageBoxIcon]::Information , ` [Windows.Forms.MessageBoxDefaultButton]::Button1, ` [Windows.Forms.MessageBoxOptions]::ServiceNotification) }
:cheers:
-
WSasifbaig
AskWoody Lounger -
WSasifbaig
AskWoody LoungerSeptember 1, 2013 at 11:00 am #1409662Aaaaaand I’m back. In less than half a year. As promised.
I tried the above mentioned script and I got this error:
Cannot find the type for custom attribute ‘Parameter ‘. Make sure that the asse
mbly that contains this type is loaded.
At D:StuffUnsortedPowershellchargealert.ps1:10 char:13
+ [Parameter <<<< (Mandatory=$False)]
+ CategoryInfo : InvalidOperation: (Parameter :Token) [], Runtime
Exception
+ FullyQualifiedErrorId : CustomAttributeTypeNotFoundIt appears that I need to install some module or enable some setting. Kindly let me know what I'm doing wrong.
-
RetiredGeek
AskWoody_MVPSeptember 1, 2013 at 12:48 pm #1409683Could you please post your version of the .ps1 file? :cheers:
-
WSasifbaig
AskWoody LoungerSeptember 2, 2013 at 9:02 am #1409814I copied all the text that you gave, saved it to a text file and named it chargealert.ps1.
I’ll paste the text below. In case there’s some formatting error on this website, you can get the actual file from here: https://dl.dropboxusercontent.com/u/16631047/Test/chargealert.ps1
Code:Param ( [Parameter (Mandatory=$False)] $BaseCapacity ) [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”) $MyBattery = ` Get-WmiObject -class BatteryStatus -ComputerName LocalHost -NameSpace rootWMI $BatteryRemaining = $MyBattery.RemainingCapacity/$BaseCapacity $Message = “” if(($BatteryRemaining -lt 0.40) -and $MyBattery.Discharging) { $Message = “Battery Low…Please Charge Me!” } Elseif(($BatteryRemaining -gt 0.85) -and $MyBattery.PowerOnline) { $Message = “Battery CHARGED above 95%…Please Unplug Me!” } if($Message -ne “”) { [Windows.Forms.MessageBox]::Show($Message, “Battery Status”, ` [Windows.Forms.MessageBoxButtons]::OK , ` [Windows.Forms.MessageBoxIcon]::Information , ` [Windows.Forms.MessageBoxDefaultButton]::Button1, ` [Windows.Forms.MessageBoxOptions]::ServiceNotification) }
-
RetiredGeek
AskWoody_MVPSeptember 2, 2013 at 11:05 am #1409843Asifbaig,
Ok, here goes with a “stupid” question.
You are running this on a machine that has a battery?
I tried it on my desktop and got errors although not the same as yours:
[noparse]
Get-WmiObject : Invalid class “BatteryStatus”
At G:bekdocsscriptsBatteryStatusV3.ps1:19 char:2
+ Get-WmiObject -class BatteryStatus -ComputerName LocalHost -NameSpace rootWMI
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
[/noparse]
But it ran just fine on my laptop.
34840-BatteryStatus
HTH :cheers: -
WSasifbaig
AskWoody LoungerSeptember 3, 2013 at 4:41 pm #1410147Yeah, I ran it on my laptop with the battery still attached to it (either that or my desktop became self-aware, disguised itself and is planning to kill me
).
And surprisingly, I ran it now and it runs fine. I restarted the system in between and that must have evacuated the gremlins…
Thank you so much for your help.
-
RetiredGeek
AskWoody_MVPSeptember 3, 2013 at 4:54 pm #1410148Glad you got it sorted! :cheers:
Viewing 13 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
9 hours, 52 minutes ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
5 hours, 54 minutes ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
12 hours, 18 minutes ago -
Return of the brain dead FF sidebar
by
EricB
2 hours, 55 minutes ago -
windows settings managed by your organization
by
WSDavidO61
7 hours ago -
Securing Laptop for Trustee Administrattor
by
PeachesP
7 hours, 13 minutes ago -
The local account tax
by
Susan Bradley
3 hours, 3 minutes ago -
Recall is back with KB5055627(OS Build 26100.3915) Preview
by
Alex5723
18 hours, 55 minutes ago -
Digital TV Antenna Recommendation
by
Win7and10
11 hours, 27 minutes ago -
Server 2019 Domain Controllers broken by updates
by
MP Support
1 day, 6 hours ago -
Google won’t remove 3rd party cookies in Chrome as promised
by
Alex5723
1 day, 8 hours ago -
Microsoft Manager Says macOS Is Better Than Windows 11
by
Alex5723
1 day, 11 hours ago -
Outlook (NEW) Getting really Pushy
by
RetiredGeek
14 hours, 4 minutes ago -
Steps to take before updating to 24H2
by
Susan Bradley
4 hours, 53 minutes ago -
Which Web browser is the most secure for 2025?
by
B. Livingston
18 hours, 30 minutes ago -
Replacing Skype
by
Peter Deegan
7 hours, 3 minutes ago -
FileOptimizer — Over 90 tools working together to squish your files
by
Deanna McElveen
1 day, 5 hours ago -
Excel Macro — ask for filename to be saved
by
nhsj
3 hours ago -
Trying to backup Win 10 computer to iCloud
by
SheltieMom
6 hours, 50 minutes ago -
Windows 11 Insider Preview build 26200.5570 released to DEV
by
joep517
3 days, 11 hours ago -
Windows 11 Insider Preview build 26120.3941 (24H2) released to BETA
by
joep517
3 days, 13 hours ago -
Windows 11 Insider Preview Build 22635.5305 (23H2) released to BETA
by
joep517
3 days, 13 hours ago -
No April cumulative update for Win 11 23H2?
by
Peobody
2 days, 1 hour ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
3 days, 13 hours ago -
Boot Sequence for Dell Optiplex 7070 Tower
by
Serge Carniol
4 days, 4 hours ago -
OTT Upgrade Windows 11 to 24H2 on Unsupported Hardware
by
bbearren
4 days, 8 hours ago -
Inetpub can be tricked
by
Susan Bradley
2 days, 16 hours ago -
How merge Outlook 2016 .pst file w/into newly created Outlook 2024 install .pst?
by
Tex265
3 days, 2 hours ago -
FBI 2024 Internet Crime Report
by
Alex5723
4 days, 12 hours ago -
Perplexity CEO says its browser will track everything users do online
by
Alex5723
1 day, 21 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.