text stringlengths 0 4.23k |
|---|
To schedule to run once |
In the run-once schedule type, the /sc once parameter is required. The /st parameter, which specifies the time that the task runs, is required. The /sd parameter, which specifies the date that the task runs, is optional, while the /mo (modifier) and /ed (end date) parameters aren't valid. |
Schtasks won't let you schedule a task to run once if the date and time specified are in the past, based on the time of the local computer. To schedule a task that runs once on a remote computer in a different time zone, you must schedule it before that date and time occurs on the local computer. |
Example |
To schedule the MyApp program to run at midnight on January 1, 2003, type: |
schtasks /create /tn MyApp /tr c:\apps\myapp.exe /sc once /sd 01/01/2003 /st 00:00 |
This example uses the /sc parameter to specify the schedule type and the /sd and /st parameters to specify the date and time. Also in this example, the local computer uses the English (United States) option in Regional and Language Options, the format for the start date is MM/DD/YYYY. |
To schedule a task to run every time the system starts |
In the on-start schedule type, the /sc onstart parameter is required. The /sd (start date) parameter is optional and the default is the current date. |
Example |
To schedule the MyApp program to run every time the system starts, type: |
schtasks /create /tn MyApp /tr c:\apps\myapp.exe /sc onstart |
In this example, the local computer uses the English (United States) option in Regional and Language Options, the format for the start date is MM/DD/YYYY. |
To schedule a task to run when a user logs on |
The on logon schedule type schedules a task that runs whenever any user logs on to the computer. In the on logon schedule type, the /sc onlogon parameter is required. The /sd (start date) parameter is optional and the default is the current date. |
Example |
To schedule a task that runs when a user logs on to a remote computer, type: |
schtasks /create /tn "Start Web Site" /tr c:\myiis\webstart.bat /sc onlogon /s Server23 |
This example 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. |
To schedule a task to run when the system is idle |
The on idle schedule type schedules a task that runs whenever there is no user activity during the time specified by the /i parameter. In the on idle schedule type, the /sc onidle parameter and the /i parameter are required. The /sd (start date) is optional and the default is the current date. |
Example |
To schedule the MyApp program to run whenever the computer is idle, type: |
schtasks /create /tn MyApp /tr c:\apps\myapp.exe /sc onidle /i 10 |
This example uses the required /i parameter to specify that the computer must remain idle for ten minutes before the task starts. |
To schedule a task to run now |
Schtasks doesn't have a Run Now option, but you can simulate that option by creating a task that runs once and starts in a few minutes. |
Example |
To schedule a task to run once, on November 13, 2020 at 2:18 P.M. local time, type: |
schtasks /create /tn MyApp /tr c:\apps\myapp.exe /sc once /st 14:18 /sd 11/13/2002 |
In this example, the local computer uses the English (United States) option in Regional and Language Options, so the format for the start date is MM/DD/YYYY. |
To schedule a task that runs with different permissions |
You can schedule tasks of all types to run with permissions of an alternate account on both the local and a remote computer. In addition to the parameters required for the particular schedule type, the /ru parameter is required and the /rp parameter is optional. |
Examples |
To run the MyApp program on the local computer, type: |
schtasks /create /tn MyApp /tr myapp.exe /sc weekly /d TUE /ru Admin06 |
This example uses the /ru parameter to specify that the task should run with the permissions of the user's Administrator account (Admin06). Also in this example, the task is scheduled to run every Tuesday, but you can use any schedule type for a task run with alternate permissions. |
In response, SchTasks.exe prompts for the run as password for the Admin06 account, and then displays a success message: |
Please enter the run as password for Admin06: ******** |
SUCCESS: The scheduled task My App has successfully been created. |
To run the MyApp program on the Marketing computer every four days, type: |
schtasks /create /tn MyApp /tr myapp.exe /sc daily /mo 4 /s Marketing /u Marketing\Admin01 /ru Reskits\User01 |
This example uses the /sc parameter to specify a daily schedule, and the /mo parameter to specify an interval of four days. Additionally, this example uses the /s parameter to provide the name of the remote computer and the /u parameter to specify an account with permission to schedule a task on the remote computer (Admin01 on the Marketing computer). Finally, this example uses the /ru parameter to specify that the task should run with the permissions of the user's non-Administrator account (User01 in the Reskits domain). Without the /ru parameter, the task would run with the permissions of the account specified by /u. |
When running this example, Schtasks first requests the password of the user named by the /u parameter (to run the command) and then requests the password of the user named by the /ru parameter (to run the task). After authenticating the passwords, schtasks displays a message indicating that the task is scheduled: |
Type the password for Marketing\Admin01:******** |
Please enter the run as password for Reskits\User01: ******** |
SUCCESS: The scheduled task My App has successfully been created. |
To run schedule the AdminCheck.exe program to run on the Public computer every Friday at 4:00 A.M.,, but only if the administrator of the computer is logged on, type: |
schtasks /create /tn "Check Admin" /tr AdminCheck.exe /sc weekly /d FRI /st 04:00 /s Public /u Domain3\Admin06 /ru Public\Admin01 /it |
This example uses the /sc parameter to specify a weekly schedule, the /d parameter to specify the day, and the /st parameter to specify the start time. It also uses the /s parameter to provide the name of the remote computer, the /u parameter to specify an account with permission to schedule a task on the remote computer, the /ru parameter to configure the task to run with the permissions of the administrator of the Public computer (Public\Admin01), and the /it parameter to indicate that the task runs only when the Public\Admin01 account is logged on. |
Note |
To identify tasks with the interactive-only (/it) property, use a verbose query (/query /v). In a verbose query display of a task with /it, the Logon Mode field has a value of Interactive only. |
/query /v |
To schedule a task that runs with system permissions |
Tasks of all types can run with permissions of the System account on both the local and a remote computer. In addition to the parameters required for the particular schedule type, the /ru system (or /ru) parameter is required, while the /rp parameter isn't valid. |
Important |
The System account doesn't have interactive logon rights. Users can't see or interact with programs or tasks run with system permissions. The /ru parameter determines the permissions under which the task runs, not the permissions used to schedule the task. Only Administrators can schedule tasks, regardless of the value of the /ru parameter. |
To identify tasks that run with system permissions, use a verbose query (/query /v). In a verbose query display of a system-run task, the Run As User field has a value of NT AUTHORITY\SYSTEM and the Logon Mode field has a value of Background only. |
/query /v |
Examples |
To schedule the MyApp program to run on the local computer with permissions of the System account, type: |
schtasks /create /tn MyApp /tr c:\apps\myapp.exe /sc monthly /d 15 /ru System |
In this example, the task is scheduled to run on the fifteenth day of every month, but you can use any schedule type for a task run with system permissions. Additionally, this example uses the /ru System parameter to specify the system security context. Because system tasks don't use a password, the /rp parameter is left out. |
In response, SchTasks.exe displays an informational message and a success message, without prompting for a password: |
INFO: The task will be created under user name (NT AUTHORITY\SYSTEM). |
SUCCESS: The Scheduled task My App has successfully been created. |
To schedule the MyApp program to run on the Finance01 computer every morning at 4:00 A.M., using system permissions, type: |
schtasks /create /tn MyApp /tr myapp.exe /sc daily /st 04:00 /s Finance01 /u Admin01 /ru System |
This example uses the /tn parameter to name the task and the /tr parameter to specify the remote copy of the MyApp program, the /sc parameter to specify a daily schedule, but leaves out the /mo parameter because 1 (every day) is the default. This example also uses the /st parameter to specify the start time, which is also the time the task will run each day, the /s parameter to provide the name of the remote computer, the /u parameter to specify an account with permission to schedule a task on the remote computer, and the /ru parameter to specify that the task should run under the System account. Without the /ru parameter, the task would run using the permissions of the account specified by the /u parameter. |
Schtasks.exe requests the password of the user named by the /u parameter and, after authenticating the password, displays a message indicating that the task is created and that it will run with permissions of the System account: |
Type the password for Admin01:********** |
INFO: The Schedule Task My App will be created under user name (NT AUTHORITY\ |
SYSTEM). |
SUCCESS: The scheduled task My App has successfully been created. |
To schedule a task that runs more than one program |
Each task runs only one program. However, you can create a batch file that runs multiple programs and then schedule a task to run the batch file. |
Using a text editor, such as Notepad, create a batch file that includes the name and fully qualified path to the .exe file required to start the Event Viewer (Eventvwr.exe) and System Monitor (Perfmon.exe) programs. |
C:\Windows\System32\Eventvwr.exe |
C:\Windows\System32\Perfmon.exe |
Save the file as MyApps.bat, open schtasks.exe, and then create a task to run MyApps.bat by typing: |
schtasks /create /tn Monitor /tr C:\MyApps.bat /sc onlogon /ru Reskit\Administrator |
This command creates the Monitor task, which runs whenever anyone logs on. It uses the /tn parameter to name the task, the /tr parameter to run MyApps.bat, the /sc parameter to indicate the OnLogon schedule type and the /ru parameter to run the task with the permissions of the user's Administrator account. |
As a result of this command, whenever a user logs on to the computer, the task starts both Event Viewer and System Monitor. |
To schedule a task that runs on a remote computer |
To schedule a task to run on a remote computer, you must add the task to the remote computer's schedule. Tasks of all types can be scheduled on a remote computer, but the following conditions must be met: |
You must have permission to schedule the task. As such, you must be logged on to the local computer with an account that is a member of the Administrators group on the remote computer, or you must use the /u parameter to provide the credentials of an Administrator of the remote computer. |
You can use the /u parameter only when the local and remote computers are in the same domain or the local computer is in a domain that the remote computer domain trusts. Otherwise, the remote computer cannot authenticate the user account specified and it cannot verify that the account is a member of the Administrators group. |
The task must have sufficient permission to run on the remote computer. The permissions required vary with the task. By default, the task runs with the permission of the current user of the local computer or, if the /u parameter is used, the task runs with the permission of the account specified by the /u parameter. However, you can use the /ru parameter to run the task with permissions of a different user account or with system permissions. |
Examples |
To schedule the MyApp program (as an administrator) to run on the SRV01 remote computer every ten days starting immediately,type: |
schtasks /create /s SRV01 /tn MyApp /tr c:\program files\corpapps\myapp.exe /sc daily /mo 10 |
This example uses the /s parameter to provide the name of the remote computer. Because the local current user is an Administrator of the remote computer, the /u parameter, which provides alternate permissions for scheduling the task, isn't necessary. |
Note |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.