16

I created a windows task and scheduled to run every 1 hour.

Every hour the task runs but am getting an warning Task Scheduler did not launch task "\Sample Task" because computer is running on batteries. User Action: If launching the task on batteries is required, change the respective flag in the task configuration. and task exits pre-maturely.

I am using SCHTASKS.exe for creating task as I need to create task taking user input from a form.

Using the command I want to remove the power option. enter image description here Is this possible?

Sunil Agarwal
  • 4,097
  • 5
  • 44
  • 80

3 Answers3

16

As you've probably already observed, schtasks.exe does not provide a command-line switch to toggle the power settings.

You basically have two solutions:

  1. You can create an XML file with the desired options, and then create the task on the command line from that XML file.

    For example, you would include the following settings element in your XML file:

    <Settings>
        <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    </Settings>
    
  2. You can write code that sets the ITaskSettings::DisallowStartIfOnBatteries property to the desired value.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • can you please provide an example of creating task using XML? – Sunil Agarwal Jan 31 '12 at 07:44
  • 2
    Thanks a lot. Got solution for creating task from XML. http://technet.microsoft.com/en-us/library/cc722156.aspx – Sunil Agarwal Jan 31 '12 at 07:54
  • OMG, I have spent so much time trying to figure out why my schtasks process would not run! (I usually use schtasks on non-laptop hardware). How can they be missing a CLI switch for this stupid option? – osprey Mar 29 '21 at 17:49
4

The easiest way may be to just switch to PowerShell. There is New-ScheduledTaskSettingsSet for that, which has a -AllowStartIfOnBatteries parameter.

rugk
  • 4,755
  • 2
  • 28
  • 55
3

easy. create the task with the wizard, then configures everything disables AC power and then export it to XML , then edit the XML and remove the line Author and ready can use and import on any computer with the AC Off and other settings intact

schtasks /create /xml " & "edited.xml" & " /tn nameTask /f"