Schtasks command details (scheduled task DOS batch processing)

Source: Internet
Author: User
Tags schtasks

Schtasks

Schedule regular running of commands and programs or within a specified period of time. Add and delete tasks from a schedule, start and stop tasks as needed, and display and Change scheduled tasks.

Create a new scheduled task.

Syntax

Schtasks/create/TNTaskname/TrTaskrun/SCSchedule[/MoModifier] [/DDay] [/MMonth[,Month...] [/IIdletime] [/STStarttime] [/SDStartdate] [/EDEnddate] [/SComputer[/U [Domain\]User/PPassword] [/Ru {[Domain\]User| "System"} [/RPPassword]/?

Parameters

/TNTaskname

The name of the task.

/TrTaskrun

Specifies the program or command that the task runs. Type a fully qualified path and file name for the executable file, script file, or batch file. If you skip this example, schtasks.exe assumes that the file isSystemroot\ System32 directory.

/SCSchedule

Specify the scheduler type. Valid values include minute, hourly, daily, weekly, monthly, once, onstart, onlogon, and onidle.

Value

Description

Minute, hourly, daily, weekly, monthly

Specifies the scheduled time unit.

Once

The task runs once on the specified date and time.

Onstart

The task runs every time the system starts. You can specify the start date or run the task at the next system startup.

Onlogon

Every time a user (any user) logs on, the task runs. You can specify a date or run the task during the next user logon.

Onidle

The task runs as long as the system is idle for a specified time. You can specify a date or run the task the next time the system is idle.

/MoModifier

Specifies the Running frequency of a task within its scheduled type. This parameter is required for the monthly plan. This parameter is valid for minute, hourly, daily, or weekly plans, but is optional. The default value is 1.

Plan type

Modifier

Description

Minute

1 ~ 1439

Task perNRun Once every minute.

Hourly

1 ~ 23

Task perNRun once every hour.

Daily

1 ~ 365

Task perNOne operation per day.

Weekly

1 ~ 52

Task perNRun once every week.

Monthly

1 ~ 12

Task perNRun once a month.

Lastday

The task runs on the last day of the month.

First, Second, Third, Fourth, last

And/dDayParameters are used together, and tasks are run at specific weeks and days. For example, on the third Wednesday of the month.

/DDirlist

Specify the day of the week or month. Valid only when used together with weekly or monthly plan.

Plan type

Date Value

Weekly

Optional. Valid value: Mon ~ Sun and * (every day ). Mon is the default value.

Monthly

When first, second, third, fourth, or last modifier (/Mo) is used, mon ~ A value in Sun. 1 ~ 31 is optional, only when there is no modifier or the modifier is 1 ~ Valid for 12 types. The default value is 1 (the first day of the month ).

/MMonth[,Month...]

Specifies a month in a year. Valid value: Jan ~ DEC and * (every month ). The/M parameter is only valid for the monthly plan. This parameter is required when the lastday modifier is used. Otherwise, it is optional. The default value is * (every month ).

/IInitialpagefilesize

Specify the number of minutes before the task starts. Type A 1 ~ An integer between 999. This parameter is only valid for the onidle plan and is required.

/STStarttime

Specify the time in HH: mm: ss24 hour format. The default value is the current local time when the command is completed. The/ST parameter is only valid for minute, hourly, daily, weekly, monthly, and once plans. It is only required for a once plan.

/SDStartdate

ToMm/Dd/YyyyFormat: Specify the task start date. The default value is the current date. The/SD parameter is valid for all plans, but only required for one plan.

/EDEnddate

Specifies the last date on which the task is scheduled to run. This parameter is optional. It is invalid for the once, onstart, onlogon, or onidle plan. By default, there is no end date for the plan.

/SComputer

Specify the name or IP address of the remote computer (with or without a backslash ). The default value is the local computer.

/U [Domain\]User

Use the permissions of a specific user account to run commands. By default, the command is run with the permissions of the user who has logged on to the computer that runs schtasks.

/PPassword

Specify the password of the user account specified in the/u parameter. This parameter is required if/u is used.

/Ru {[Domain\]User| "System "}

Run the task with the permissions of the specified user account. By default, you can log on to the computer on which schtasks runs to run the task.

Value

Description

   

[Domain\}User?

User Account.

"System" or ""

Specifies the nt authority \ SYSTEM account used by the operating system.

/PPassword

Password of the user account, which is specified in the/u parameter. If you skip this authorization when specifying a user's account, schtasks.exe will prompt you to enter the password without displaying the entered text. If you use the nt authority \ SYSTEM account permission to run a task without a password, schtasks.exe will not prompt for a password.

/?

Display help at the command prompt.

 

Example

The scheduled task runs every 20 minutes.

The following command plans the Security script sec. vbs to run every 20 minutes. Because the command does not contain the start date or time, the task starts 20 minutes after the command is completed, and then runs every 20 minutes every time the system runs it. Note that the security script source file is located on a remote computer, but the task is scheduled and executed on the local computer.

Schtasks/create/SC minute/Mo 20/TN "Security SCR limit PT"/tr \ central \ data \ SCR limit PTS \ sec. vbs

 

Example

The scheduled command is run every hour after five minutes.

The following command schedules the MyApp to run every hour from five minutes after midnight. Because the/Mo parameter is ignored, the command uses the default value of the hourly plan, that is, every (1) hour. If the command is generated after A.M, the program will run the next day.

Schtasks/create/SC hourly/ST 00:05:00/TN "My app"/TR c: \ apps \ myapp.exe

Scheduled commands run once every five hours

The following command plans that the MyApp will run every five hours from the first day of June 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 the 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

 

Example

Scheduled tasks run once a day

The following example plans to run the MyApp program at a.m. every day until the end of June December 31, 2001. Because the/Mo parameter is ignored, the default interval 1 is used to run commands every day.

Schtasks/create/TN "My app"/TR c: \ apps \ myapp.exe/SC daily/ST 08:00:00/ed 12/31/2001

Scheduled tasks run once every other day

 

Example

Scheduled tasks run every six weeks

The following command plans that the MyApp program runs on a remote computer every six weeks. This command uses the/Mo parameter to specify the interval. It also uses the/S parameter to specify the remote computer and uses the/ru parameter to schedule tasks to run with the Administrator account permissions of the user. Schtasks.exe prompts you to enter the Administrator account password because/RPGs is ignored.

In addition, because the command is run remotely, all the paths in the command, including the path to myapp.exe, all point to the path on the remote computer.

Schtasks/create/TN "My app"/TR c: \ apps \ myapp.exe/SC weekly/Mo 6/s server16/ru admin01

Scheduled tasks run on Friday every week

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.