Can I create a task in task scheduler that starts when a specific battery level reaches on idle computer to go to sleep? Windows does give option to make computer to go to sleep at specific battery level but it doesnt care if laptop is idle or not.

  • Did you find any way to make it work? – pilau Sep 24 '14 at 0:52

I got it!

I made a scheduled task that triggers when the computer is idle, and repeatedly runs a batch file that checks if the battery is discharging and how many percent it carries.

If the battery is discharging (ie, laptop is not plugged to mains), and the battery is charged 25% or less, it will immediately put the computer to sleep (or hibernate, if it's turned on already).

The task is set to repeat itself (ie, run the batch file) every 5 minutes indefinitely. Also, make sure you set the following conditions: Conditions for idle trigger

I based my batch script on battstat.bat from here: http://www.robvanderwoude.com/wmiexamples.php

You will find my script below.


:: Localize variables

:: Use WMI to retrieve battery status information
FOR /F "tokens=*  delims="  %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryStatus              Get PowerOnline^,RemainingCapacity  /Format:list ^| FIND "="')     DO SET  Battery.%%A
FOR /F "tokens=*  delims="  %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryFullChargedCapacity Get FullChargedCapacity             /Format:list ^| FIND "="')     DO SET  Battery.%%A

:: Calculate runtime left and capacity
SET /A Battery.RemainingCapacity = ( %Battery.RemainingCapacity%00 + %Battery.FullChargedCapacity% / 2 ) / %Battery.FullChargedCapacity%

:: Display results
IF /I "%Battery.PowerOnline%"=="FALSE" (
    IF %Battery.RemainingCapacity% LEQ 25 (
        Rundll32.exe Powrprof.dll,SetSuspendState Sleep

:: End localization
IF "%OS%"=="Windows_NT" ENDLOCAL
  • Ill let u know if it works for me.. – labeebahmad32 Sep 25 '14 at 6:41
  • @labeebahmad32 great - let me know :) – pilau Sep 25 '14 at 10:53
  • @labeebahmad32 did it work out for you eventually? – pilau Jan 19 '15 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.