Search code examples
windowsscheduling

Scheduler task indefinite time duration on Windows Server 2003/2008


Schtasks /create /s $server /ru $user /rp $password /tn $taskName /sc MINUTE /mo $intervalMin /tr $cmd

This command creates a task in scheduler to be executed each minute.

  • On Windows Server 2008 duration is 'Indefinite'
  • On Windows Server 2003 duration is '1 day'

How to resolve this weird behaviour?


Solution

  • The solution is to create the task this way:

    schtasks /create /s $server /sd $startdate /st $starttime /ru $user /rp $password /tn $taskName /sc daily /mo $scheduleDays /tr $cmd /RI $intervalMin /DU $duration
    

    Create daily task, set /RI = 1 (minute) and /DU = "24:00" /mo = 1(day)

    The task will be executed forever each minute on Server 2003‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎ ‎‎‎‎‎‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎