Change settings for power for windows scheduled task

Sunil Agarwal picture Sunil Agarwal · Jan 31, 2012 · Viewed 13.9k times · Source

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?

Answer

Cody Gray picture Cody Gray · Jan 31, 2012

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.