user841311
user841311

Reputation: 597

Change the start time of tasks by 1 hour using schtasks.exe

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

Answers (2)

VoteCoffee
VoteCoffee

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

Ansgar Wiechers
Ansgar Wiechers

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

Related Questions