Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default scheduled task process priority in Windows

I've been checking this for a while now. We have a script that creates a scheduled task and it seems that as described in many places across the net, the task priority this process and its descendants receive is 7:BelowNormal

Now this causes many issues in our testing environment which I'd like to avoid

The question here is whether I could create a GPO to override Windows' default scheduled task priority so that all new scheduled tasks will receive priority X (X being 'Normal' in my case)

I know there's an option to set the scheduled task priority upon creation but I'd like to avoid this so every new task will have a correct default priority and not the below-normal one

Thanks in advance

like image 280
Ohad Benita Avatar asked Nov 09 '17 09:11

Ohad Benita


2 Answers

You can edit your existing task by adding the settings option

$currentTask = Get-ScheduledTask -TaskName $taskName 
$settings = New-ScheduledTaskSettingsSet
$settings.Priority = 4
Set-ScheduledTask -TaskName $taskName -Trigger $currentTask.Triggers -Action $currentTask.Actions -Settings $settings -User "user" -Password "pass"
like image 171
Alex Portnoy Avatar answered Oct 13 '22 19:10

Alex Portnoy


Another way of doing this, without using powershell:

  1. Export the task from the GUI: in the Task Scheduler, right-click the task and select "Export…" and save the exported task in a file

  2. Change the priority
    2.1 Open the file in a text editor (like Notepad). This is the XML that defines the task. Each action will have a section, which contains <Settings>, which contains a <Priority> element.
    2.2 Change the value. The default value, for “below normal”, is 7. You can use either 6, 5, or 4 for “normal” priority. You will not usually want to go above “normal”. 6 will probably work for you.
    2.3 Save the file (for example, "c:\mytask.xml")

  3. Import the task using command line/schtasks:
    schtasks /DELETE /tn "\TASKSCHEDULER-FOLDER-PATH\TASK-IMPORT-NAME" (you need to first remove the existing task, to create a new one from the command line using schtasks)
    schtasks /create /xml "c:\mytask.xml" /tn "\TASKSCHEDULER-FOLDER-PATH\TASK-IMPORT-NAME"

I had 220 machines to do that, so I did it this way. Since all machines had the same configuration, I could copy the same XML file to all machines and recreate the scheduled task based on the XML. See a little more details on the different priorities here. This answer was based on this article.

like image 38
msb Avatar answered Oct 13 '22 18:10

msb