Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change settings for power for windows scheduled task

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?

like image 423
Sunil Agarwal Avatar asked Jan 31 '12 06:01

Sunil Agarwal


People also ask

How do I change my Task Scheduler settings?

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.

Can power users run Scheduled Tasks?

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.

How do I grant permission to run a scheduled task?

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).


2 Answers

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

like image 51
rugk Avatar answered Oct 15 '22 04:10

rugk


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.

like image 14
Cody Gray Avatar answered Oct 15 '22 03:10

Cody Gray