Reputation: 597
Is it possible to move the start or run time of scheduled tasks in Windows server 2003 machine by 1 hour without hardcoding the time using /ST paramter of schtasks command? I also don't want to use Scheduled Tasks GUI because it is a lengthy process using it for many tasks.
For eg. if task A run at 8 AM and task B at 10 AM, I want to move them to 9 AM and 11 AM respectively. If it's not possible, please suggest better ways of doing it. Thanks in advance!
Upvotes: 0
Views: 2324
Reputation: 5117
Can't be done with schtask.exe
You can't use the /st switch with the /change switch. You'd have to delete and create. But you would risk losing advanced options that you can't see with Schtask.exe. Basically you'll need to look at powershell instead to accomplish what you want.
Upvotes: 0
Reputation: 200503
AFAIK schtasks
does not provide a way to change the schedule relative to the existing schedule. You could query the current schedule from the task and then modify it accordingly:
setlocal EnableDelayedExpansion
for /f "tokens=5" %%t in (
'schtasks /query /tn foo /fo list ^| find /i "next run time:"'
) do (
if "%%t"="08:00:00" (
schtasks /change /tn foo /st 09:00
else if "%%t"="10:00:00" (
schtasks /change /tn foo /st 11:00
)
)
Upvotes: 1