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?
Open Task Scheduler, and select the task that you want to change. Click on the Properties tab from the Action menu to open the Task Properties dialog box. Click on the General tab to view the task's general settings that you can modify.
You can achieve your goal by simply granting those users the permission on C:\windows\tasks folder. It will grant the Power Users group the full control permission to create/view/run/stop/modify scheduled tasks on the server.
Scheduled tasks are saved in C:\Windows\System32\Tasks folder as xml files (with no extension). To allow non-admin users to view and run a task, find the task(s) in question and change permissions to allow Read and execute for your chosen user or group (as you would for any other file or directory).
The easiest way may be to just switch to PowerShell. There is New-ScheduledTaskSettingsSet
for that, which has a -AllowStartIfOnBatteries
parameter.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With