Transfer: https://www.cnblogs.com/ruofengzhishang/p/3859773.html
Schtasks
Schedules commands and programs to run periodically or at a specified time. Add and delete from the schedule the task as needed to start and stop tasks, display and change scheduled tasks.
Create a new scheduled task.
grammar
schtasks/create/tnTaskName/trTaskRun/scschedule[/momodifier][/dday][/mmonth[,month...][/iIdleTime][/stStartTime][/sdStartDate][/edEndDate][/scomputer[/u[domain\]user/ppassword]][/ru{[Domain\]User|"System"} [/rpPassword]]/?
parameter
/tn TaskName
Specify the name of the task.
/ tr TaskRun
Program or command to run the specified task. Type the executable file, a script or batch file fully qualified path and file name. If you omit the path, SchTasks.exe will assume the file Systemroot \ System32 directory under.
/sc schedule
Specify the type of plan. Valid values are MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE.
value |
Explanation |
MINUTE、HOURLY、DAILY、WEEKLY、MONTHLY |
Time units specified scheme. |
ONCE |
Task runs once at a specified date and time. |
ONSTART |
Task runs every time the system starts. You can specify a start date, time or the next time the system starts running tasks. |
ONLOGON |
Every time a user (any user) to log the task runs. You can specify the date, time or the next time the user logs on to run the task. |
ONIDLE |
As long as the system is idle for a specified period of time, the task will run. You can specify a date, or run the task the next time the system is idle. |
/ Mo Modifier
Specify task run frequency within its program type. This parameter is required for a MONTHLY schedule. For MINUTE, HOURLY, DAILY, or WEEKLY schedule, this parameter is valid, but optional. The default is 1.
Plan Type |
Modifiers |
Explanation |
MINUTE |
1~1439 |
Each task n run time minutes. |
HOURLY |
1~23 |
Task every n hour run time. |
DAILY |
1~365 |
Each task n run once day. |
WEEKLY |
1~52 |
Each task n run once week. |
MONTHLY |
1~12 |
Task every n month run once. |
LASTDAY |
In the last month the task runs day. |
|
FIRST、SECOND、THIRD、FOURTH、LAST |
And / d Day use common parameters, and specific days of week and run the task. For example, the third Wednesday of the month. |
/ d dirlist
Specifies the week or day of the month. WEEKLY or MONTHLY schedule only with the use of common valid.
Plan Type |
Date values |
WEEKLY |
Optional. Valid values are MON ~ SUN and * (every day). MON is the default. |
MONTHLY |
In use FIRST, SECOND, THIRD, FOURTH, or LAST modifier (/ mo), requires a MON value of ~ SUN. 1 to 31 is optional, only with no modifier or modifier is 1 to 12 types. The default value is 1 (the first day of the month). |
/m month[,month...]
Designated month of the year. Valid values are JAN ~ DEC and * (every month). / M parameter is valid only with a MONTHLY schedule. When LASTDAY modifier is used, this parameter is required. Otherwise, it is optional, the default value is * (every month).
/i InitialPageFileSize
Prior to specify how many minutes the computer is idle task starts. Type integer between 1 to 999. This parameter is only valid for ONIDLE plan, but necessary.
/st StartTime
MM:: SS24 hour format specify the time to HH. The default value is the current local time when the command completes. / St parameter is valid only for a MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, and ONCE schedule. For only ONCE plan is required.
/sd StartDate
To MM / DD / YYYY date format specified task started. The default value is the current date. / sd parameter is valid for all the programs, but only for a ONCE schedule is required.
/ed EndDate
The last date specified tasks scheduled to run. This parameter is optional. It is not valid for ONCE, ONSTART, ONLOGON or ONIDLE plan. By default, the program no end date.
/s Computer
Specify the remote computer name or IP address (with or without backslashes). The default is the local computer.
/u [domain\]user
Permission to use a specific user account to run the command. By default, the logged on user's computer to run SchTasks permission to run the command.
/p password
Specifies the password specified in the / u parameter user account. If the / u parameter, the parameter is required.
/ru {[Domain\]User|"System"}
Use the specified user account permissions to run the task. By default, users log in to use the rights to run tasks on the computer running the SchTasks.
value |
Explanation |
[domain\}User? |
Specifies the user account. |
"System"或"" |
Specify the operating system used by NT Authority \ System account. |
/p Password
Specifies the password for the user account, the user account specified in the / u parameter. If you omit this parameter specifies the user account when, SchTasks.exe text will prompt you for a password and do not appear typed. Use NT Authority \ System account permissions to run the task does not require a password, SchTasks.exe will not ask for the password prompt.
/?
Displays help at the command prompt.
example
Scheduled task to run every 20 minutes.
The following command schedules a security script Sec.vbs run every 20 minutes. Since the command does not include a starting date or time, in order to complete the task 20 minutes after the start, after which it runs whenever the system is running every 20 minutes. Please note that the security script source file is located on a remote computer, but plan and execute tasks on the local computer.
schtasks /create /sc minute /mo 20 /tn "Security scrīpt" /tr \\central\data\scrīpts\sec.vbs
example
Plans to run a command when five minutes past every hour.
The following command schedules the MyApp program to run every hour after midnight from five minutes. Because ignoring the / mo parameter, the command uses the default value is small program, that every (1) hour. If the command generated after 12:05 AM, the program will run until the next day.
schtasks /create /sc hourly /st 00:05:00 /tn "My App" /tr c:\apps\myapp.exe
Program command to run once every five hours
The following command schedules the MyApp program in March 2001, the first day of every five hours of operation from time. It uses the / mo parameter to specify the time interval, using the / sd parameter to specify a start date. Since the command does not specify a start time, the current time is used as the starting time.
schtasks /create /sc hourly /mo 5 /sd 03/01/2001 /tn "My App" /tr c:\apps\myapp.exe
schtasks create daily
example
Scheduled task to run once a day
The following example schedules the MyApp program once, until December 31, 2001 at 8:00 AM the end of a day of running. Because it omits the / mo parameter, so the default interval of 1 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
Scheduled task to run every other day
example
Scheduled task 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, use the / ru parameter to schedule the task to run with Administrator account rights of the user. Because ignoring the / rp parameter, SchTasks.exe user will be prompted to enter the Administrator account password.
Further, since the remote operation command, so that 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
Scheduled task to run every other week on Friday