Naplánované úlohy aneb automatické spuštění scriptu

Naplánování úlohy z příkazové řádky lze pomocí příkazu SCHTASKS nebo AT. Ve Windows XP je nutné používat příkazy podle jazyku instalace Windows. Ve Windows 7 se příkazy zadávají v angličtině.

Příkaz AT plánuje spouštění příkazů a programů v počítači v zadaném čase a datu. Aby bylo možné příkaz AT použít, musí být spuštěna služba Plánovač úloh.

Win7, Win2K
at \\computername time /interactive | /every:date,... /next:date,... command
at \\computername id /delete | /delete/yes

Umožňuje správci vytvořit, odstranit, vyhledat, změnit, spustit a ukončit naplánované úlohy v místním nebo vzdáleném systému.

WinXP
SCHTASKS /Create [/S systém [/U uživatelské_jméno [/P heslo]]] [/RU uživatelské_jméno [/RP heslo]] 
/SC plán [/MO modifikátor] [/D den] [/I časový_limit_nečinnosti] /TN název_úlohy 
/TR úloha_ke_spuštění [/ST čas_spuštění] [/M měsíce] [/SD počáteční_datum] [/ED koncové_datum]

Win 7
SCHTASKS /Create [/S systém [/U uživatelské_jméno [/P [heslo]]]] [/RU uživatelské_jméno [/RP heslo]] 
/SC plán [/MO modifikátor] [/D den] [/M měsíce] [/I časový_limit_nečinnosti] /TN název_úlohy 
/TR úloha_ke_spuštění [/ST čas_spuštění] [/RI interval] [ {/ET čas_ukončení | /DU trvání} [/K] [/XML soubor_xml] [/V1]] [/SD datum_spuštění] [/ED datum_ukončení] [/IT | 
/NP] [/Z] [/F]

Příklad použití v WinXP eng a Win7 (pro CZ verzi používat Min., Hod., Denně, Týdně, Měsíčně):
Automatické spuštění scriptu každý den v 1 hodinu. 
SCHTASKS /Create /SC DAILY /TN "Název úlohy" /TR “c:\cesta ke scriptu\nazev-souboru.exe” /ST 1:00
Automatické spuštění scriptu každý den po pěti minutách od 6 do 12hodin Win 7. 
SCHTASKS /Create /ST 6:00 /ET 12:00 /TN MojeUloha /SC minute /MO 5 /TR "C:\scripty\spust_script.bat"
Každých 20 minut na WinXP
schtasks /create /sc minute /mo 20 /tn "Security Script" /tr \\central\data\scripts\sec.vbs
Smazání úlohy
schtasks /delete /TN "nazev-ulohy"

Více na adresách:

https://support.microsoft.com/cs-cz/kb/313565
https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx
https://technet.microsoft.com/en-us/library/cc725744.aspx
https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc hourly [/mo {1 – 365}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a command that runs every hour at five minutes past the hour

The following command schedules the MyApp program to run hourly beginning at five minutes past midnight. Because the /mo parameter is omitted, the command uses the default value for the hourly schedule, which is every (1) hour. If this command is issued after 12:05 A.M., the program will not run until the next day.

schtasks /create /sc hourly /st 00:05:00 /tn „My App“ /tr c:\apps\myapp.exe

To schedule a command that runs every five hours

The following command schedules the MyApp program to run every five hours beginning on the first day of March 2001. It uses the /mo parameter to specify the interval and the /sd parameter to specify the start date. Because the command does not specify a start time, the current time is used as the start time.

schtasks /create /sc hourly /mo 5 /sd 03/01/2001 /tn „My App“ /tr c:\apps\myapp.exe

schtasks create daily

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc daily [/mo {1 – 365}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a task that runs every day

The following example schedules the MyApp program to run once a day, every day, at 8:00 A.M. until December 31, 2001. Because it omits the /mo parameter, the default interval of 1 is used to run the command every day.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc daily /st 08:00:00 /ed 12/31/2001

To schedule a task that runs every other day

The following example schedules the MyApp program to run every other day at 1:00 P.M. (13:00) beginning on December 31, 2001. The command uses the /mo parameter to specify an interval of two (2) days.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc daily /mo 2 /st 13:00:00 /sd 12/31/2001

schtasks create weekly

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc weekly [/d {MON – SUN | *}] [/mo {1 – 52}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a task that runs every six weeks

The following command schedules the MyApp program to run on a remote computer every six weeks. The command uses the /mo parameter to specify the interval. It also uses the /s parameter to specify the remote computer and the /ru parameter to schedule the task to run with the permissions of the user’s Administrator account. Because the /rp parameter is omitted, SchTasks.exe prompts the user for the Administrator account password.

Also, because the command is run remotely, all paths in the command, including the path to MyApp.exe, refer to paths on the remote computer.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc weekly /mo 6 /s Server16 /ru Admin01

To schedule a task that runs every other week on Friday

The following command schedules a task to run every other Friday. It uses the /mo parameter to specify the two-week interval and the /d parameter to specify the day of the week. To schedule a task that runs every Friday, omit the /mo parameter or set it to 1.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc weekly /mo 2 /d FRI

schtasks create monthly

Syntax

General Monthly Schedule Syntax : schtasks /create /tn TaskName /tr TaskRun /sc monthly [/mo {FIRST | SECOND | THIRD | FOURTH | LAST | LASTDAY] [/d {MONSUN | 131}] [/m {JANDEC[,JANDEC…] | *}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Specific Week Syntax : schtasks /create /tn TaskName /tr TaskRun /sc monthly /mo {FIRST | SECOND | THIRD | FOURTH | LAST/d {MONSUN} [/m {JANDEC[,JANDEC…] | *}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Lastday Syntax : schtasks /create /tn TaskName /tr TaskRun /sc monthly /mo LASTDAY /m {JANDEC[,JANDEC…] | *} [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Specific Date Syntax : schtasks /create /tn TaskName /tr TaskRun /sc monthly /d {131} [/m {JANDEC[,JANDEC…] | *}] [/st StartTime] [/sd StartDate] [/ed EndDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Examples

To schedule a task for the first day of every month

The following command schedules the MyApp program to run on the first day of every month. Because the default modifier is none (no modifier), the default day is day 1, and the default month is every month, the command does not need any additional parameters.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc monthly

To schedule a task for the last day of every month

The following command schedules the MyApp program to run on the last day of every month. It uses the /mo parameter to specify the last day of the month and the /m parameter with the wildcard character (*) to indicate that the program runs on the last day of every month.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc monthly /mo lastday /m *

To schedule a task that runs every three months

The following command schedules the MyApp program to run every three months. It uses the /mo parameter to specify the interval.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc monthly /mo 3

To schedule a task for the second Sunday of every month

The following command schedules the MyApp program to run on the second Sunday of every month. It uses the /mo parameter to specify the second week of the month and the /d parameter to specify the day.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc monthly /mo SECOND /d SUN

To schedule a task for the 15th days of May and June

The following command schedules the MyApp program to run on May 15 and June 15 at 3:00 PM (15:00). It uses the /d parameter to specify the date and the /m parameter to specify the months. It also uses the /st parameter to specify the start time.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc monthly /d 15 /m MAY,JUN /st 15:00:00

schtasks create once

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc once /st StartTime /sd StartDate [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a task that runs one time

The following command schedules the MyApp program to run at midnight on January 1, 2002. It uses the /ru parameter to run the task with the permissions of the user’s Administrator account and the /rp parameter to provide the password for the Administrator account.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc once /st 00:00:00 /sd 01/01/2002 /ru Admin23 /rp p@ssworD1

schtasks create onstart

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc onstart [/sd StartDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a task that runs every time the system starts

The following command schedules the MyApp program to run every time the system starts, beginning on March 15, 2001:

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc onstart /sd 03/15/2001

schtasks create onlogon

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc onlogon [/sd StartDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a task that runs when a user logs on to a remote computer

The following command schedules a batch file to run every time a user (any user) logs on to the remote computer. It uses the /s parameter to specify the remote computer. Because the command is remote, all paths in the command, including the path to the batch file, refer to a path on the remote computer.

schtasks /create /tn „Start Web Site“ /tr c:\myiis\webstart.bat /sc onlogon /s Server23

schtasks create onidle

Syntax

schtasks /create /tn TaskName /tr TaskRun /sc onidle /iIdleTime [/sd StartDate] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | „System“} [/rp Password]]

Example

To schedule a task that runs whenever the computer is idle

The following command schedules the MyApp program to run whenever the computer is idle. It uses the required /i parameter to specify that the computer must remain idle for ten minutes before the task starts.

schtasks /create /tn „My App“ /tr c:\apps\myapp.exe /sc onidle /i 10

Pomohl Vám článek a chcete nás odměnit? Pošlete nám platbu přes paypal nebo na BTC peněženku 1bBr5iNS337NVzWjkvvH31bjmDvH4kfGb