How to schedule a task for multiple days of a month using schtasks.exe?
Solution 1
Schedule two monthly tasks. One for the 5th and one for the 15th.
Solution 2
You could create a task using an XML file:
schtasks /Create /XML xmlfile
(see documentation).
The XML should contain a <ScheduleByMonth>
section:
<ScheduleByMonth>
<DaysOfMonth>
<Day>5</Day>
<Day>15</Day>
</DaysOfMonth>
...
You can create the XML file using the GUI version of the Task Scheduler. Use the "Export" function. Here is an example file:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2010-01-21T13:24:17.7449831</Date>
<Author>DOMAIN\Username</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2010-01-21T13:23:34.4046495</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByMonth>
<DaysOfMonth>
<Day>5</Day>
<Day>15</Day>
</DaysOfMonth>
<Months>
<January />
<February />
<March />
<April />
<May />
<June />
<July />
<August />
<September />
<October />
<November />
<December />
</Months>
</ScheduleByMonth>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>DOMAIN\Username</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<ShowMessage>
<Title>Test Message</Title>
<Body>TThis is a test task message.</Body>
</ShowMessage>
</Actions>
</Task>
dereli
Updated on September 17, 2022Comments
-
dereli over 1 year
Since task scheduler API has been changed after Vista & Server 2008, scheduling a task with schtasks is (as much as I know) the only way that works on both Windows 2003 Server and Windows 2008 Server.
I need to create a task that will run every on 5th and 20th of each month. Is this possible with schtasks.exe?
Creating a scheduled task that will run on every sunday and monday of a week is possible with:
schtasks /create /tn test /tr "cmd.exe" /sc weekly /d mon,sun
But with the same aspect, any of the following is not working.
schtasks /create /tn test /tr "cmd.exe" /sc monthly /d 5,15
schtasks /create /tn test /tr "cmd.exe" /sc monthly /d "5 15"
Any ideas?
-
jwg over 9 yearsThe
mon,sun
syntax doesn't work for me either. -
dereli over 9 yearsHaving a non-English locale settings may cause this, I believe.
-
jwg over 9 yearsNot sure, because
/d "mon sun"
does work.
-
-
joeqwerty over 14 years+1. Simple and ingenious.
-
dereli over 14 years/xml argument is not supported on Windows 2003 Server.
-
dereli over 14 yearsActually, I don't like this, but this seems to be the only solution.