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. Is this possible?
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:
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>
You can write code that sets the ITaskSettings::DisallowStartIfOnBatteries
property to the desired value.