Scheduled tasks windows server 2012 r2

Содержание
  1. Scheduled tasks windows server 2012 r2
  2. Asked by:
  3. Question
  4. All replies
  5. Schtasks
  6. Remarks
  7. schtasks create
  8. Combined syntax and parameter descriptions
  9. Syntax
  10. Parameters
  11. /d Day[,Day. ] | *
  12. /m Month[,Month. ]
  13. To schedule a task that runs every N minutes
  14. Minute Schedule Syntax
  15. Remarks
  16. Examples
  17. To schedule a task that runs every 20В minutes
  18. To schedule a task that runs every 100В minutes during non-business hours
  19. To schedule a task that runs every N hours
  20. Hourly Schedule Syntax
  21. Remarks
  22. Examples
  23. To schedule a task that runs every five hours
  24. To schedule a task that runs every hour at five minutes past the hour
  25. To schedule a task that runs every 3 hours for 10 hours
  26. To schedule a task that runs every N days
  27. Daily Schedule Syntax
  28. Remarks
  29. Examples
  30. To schedule a task that runs every day
  31. To schedule a task that runs every 12 days
  32. To schedule a task that runs every 70 days if I am logged on
  33. To schedule a task that runs every N weeks
  34. Weekly Schedule Syntax
  35. Remarks
  36. Examples
  37. To schedule a task that runs every six weeks
  38. To schedule a task that runs every other week on Friday
  39. To schedule a task that runs every N months
  40. Syntax
  41. Remarks
  42. Examples
  43. To schedule a task that runs on the first day of every month
  44. To schedule a task that runs every three months
  45. To schedule a task that runs at midnight on the 21st day of every other month
  46. To schedule a task that runs on a specific day of the week
  47. Weekly Schedule Syntax
  48. Remarks
  49. Examples
  50. To schedule a task that runs every Wednesday
  51. To schedule a task that runs every eight weeks on Monday and Friday
  52. To schedule a task that runs on a specific week of the month
  53. Specific Week Syntax
  54. Remarks
  55. Examples
  56. To schedule a task for the second Sunday of every month
  57. To schedule a task for the first Monday in March and September
  58. To schedule a task that runs on a specific date each month
  59. Specific date syntax
  60. Remarks
  61. Examples
  62. To schedule a task for the first day of every month
  63. To schedule a task for the 15th days of May and June
  64. To schedule a task that runs on the last day of a month
  65. Last day syntax
  66. Remarks
  67. Examples
  68. To schedule a task for the last day of every month
  69. To schedule a task at 6:00 P.M. on the last days of February and March
  70. To schedule a task that runs once
  71. Syntax
  72. Remarks
  73. Examples
  74. To schedule a task that runs one time
  75. To schedule a task that runs every time the system starts
  76. Syntax
  77. Remarks
  78. Examples
  79. To schedule a task that runs when the system starts
  80. To schedule a task that runs when a user logs on
  81. Syntax
  82. Remarks
  83. Examples
  84. To schedule a task that runs when a user logs on to a remote computer
  85. To schedule a task that runs when the system is idle
  86. Syntax
  87. Remarks
  88. Examples
  89. To schedule a task that runs whenever the computer is idle
  90. To schedule a task that runs now
  91. Syntax
  92. Examples
  93. To schedule a task that runs a few minutes from now.
  94. To schedule a task that runs with different permissions
  95. Examples
  96. To run a task with Administrator permissions on the local computer
  97. To run a task with alternate permissions on a remote computer
  98. To run a task only when a particular user is logged on
  99. To schedule a task that runs with system permissions
  100. Examples
  101. To run a task with system permissions
  102. To run a task with system permissions on a remote computer
  103. To schedule a task that runs more than one program
  104. To schedule a task that runs on a remote computer
  105. Examples
  106. An Administrator schedules a task on a remote computer
  107. A user schedules a command on a remote computer (Case 1)
  108. A user schedules a command on a remote computer (Case 2)
  109. Remarks
  110. schtasks change

Scheduled tasks windows server 2012 r2

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Asked by:

Question

I have a GPO which creates a scheduled Task on all of my servers. The policy works fine on 2003/2008/2008R2. But it is NOT working on 2012/R2. The policy is applied but the Task is not created.

All replies

Task was created like this:

  • GPMC -> Computer Configuration -> Preferences -> Scheduled Tasks
  • Right-Click -> New -> «Scheduled Task»
  • Gave a name, a schedule and a task
  • Thats it

2003: GPO applied, scheduled Task created
2008: GPO applied, scheduled Task created
2008 R2: GPO applied, scheduled Task created
2012: GPO applied, Task NOT created
2012 R2: GPO applied, Task NOT created

>>2012: GPO applied, Task NOT created

>>2012 R2: GPO applied, Task NOT created

Does this mean that in the group policy result report, we could see the scheduled task item applied but the task didn’t actually run on these two servers?

Before going further, we can check Event Viewer to see if some related events were logged. Besides, we can go to the location C:\Windows\Tasks\SchedLgU.txt to check the scheduled task log.

Best regards,
Frank Shen

thank you for your reply!

Exactly. in gpresult I can see the policy which should create the Scheduled task under » Applied GPOs».

C:\Windows\Tasks\ is empty.

What task did we run? Please make sure that the system accounts have the permissions to run the task.

>>Exactly. in gpresult I can see the policy which should create the Scheduled task under « Applied GPOs».

Did you see the scheduled task preference item in the report? In order to get a better report, we can run gpresult/h c:\gpreport.html with admin privileges to collect the report.

If we can see the item applied successfully in the above report, we can open Task Scheduler to check if we can find the task. If we can find the task, we can check the history of the task.

View Task Properties and History

what do you mean with » Did you see the scheduled task preference item in the report?»
Sure I can see the policy which should create the scheduled task at «Applied policies». That says me, that the policy is applied. But nothing happens. there is no scheduled task created in the scheduler.
The scheduled task is running with BUILTIN\SYSTEM and runs a script which creates a report. On 2008/2008R2 the SAME policy is working fine.

I figured out this issue in my case. I’m not sure exactly what fixed it — but I believe it’s because I was setting the runas to BUILTIN\SYSTEM and I should have just left it as default «run only when user was logged in» — as that defaults to the system account. So instead I typed in simply «SYSTEM». I also created a totally new GPO using a 2012R2 server (instead of creating it from my usually routine which is to use my desktop — Windows 7). Not sure if that made a difference.

GPP for task schedule creation not creating task for Windows 2012 R2 Systems:

I recently ran into the same issue. Contacted MS. The GPP for the task was showing that it applied but the task was not being created.

MS advised that when creating a scheduled task via GPP(Group Policy Preference) that I needed to select NEW> Scheduled Task (At least Windows 7) instead of just New>Scheduled Task. As soon as I did that the GPP applied and created the task on the Windows 2012 R2 systems.

I asked for documentation and all I was given was this:

It does not mention the 4 options I was advised to use.

I think this is determined by DFL/FFL. Not sure though. I also run with highest privileges(SYSTEM).

I’m seeing the same behaviour still as well, no tasks being created on 2012 r2 servers but the same policy was applying just fine to 2008 R2 servers, and creating the task succesfully. and I noticed on my reports I was seeing this (but only if you run gpresult /h c:\whatever.html using /v and piping to text won’t show the error)

POLICY-NAME SPECIAL ALERT — AD / SYSVOL Version Mismatch

That’s when I found this hotfix.

Not that it matters for me, turns out there’s also a bug when creating tasks that run as elevated admin user, the task gets created — but doesnt actually have admin rights. Deleting the task and re-creating it with exactly the same settings specified in the GPO, only locally on the machine via task scheduler — works just fine. Hope this saves someone else from pulling their hair out for 4 hrs.

Schtasks

Applies To: Windows Server 2008, Windows Server 2012, Windows 8

Schedules commands and programs to run periodically or at a specific time. Adds and removes tasks from the schedule, starts and stops tasks on demand, and displays and changes scheduled tasks.

To view the command syntax, click one of the following commands:

Remarks

SchTasks.exe performs the same operations as Scheduled Tasks in Control Panel. You can use these tools together and interchangeably.

Schtasks replaces At.exe, a tool included in previous versions of Windows. Although At.exe is still included in the WindowsВ ServerВ 2003 family, schtasks is the recommended command-line task scheduling tool.

The parameters in a schtasks command can appear in any order. Typing schtasks without any parameters performs a query.

Permissions for schtasksВ

You must have permission to run the command. Any user can schedule a task on the local computer, and they can view and change the tasks that they scheduled. Members of the Administrators group can schedule, view, and change all tasks on the local computer.

To schedule, view, or change a task on a remote computer, you must be 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 in a /create or /change operation 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 permission to run. The permissions required vary with the task. By default, tasks run with the permissions of the current user of the local computer, or with the permissions of the user specified by the /u parameter, if one is included. To run a task with permissions of a different user account or with system permissions, use the /ru parameter.

To verify that a scheduled task ran or to find out why a scheduled task did not run, see the Task Scheduler service transaction log, SystemRoot\SchedLgU.txt. This log records attempted runs initiated by all tools that use the service, including Scheduled Tasks and SchTasks.exe.

On rare occasions, task files become corrupted. Corrupted tasks do not run. When you try to perform an operation on corrupted tasks, SchTasks.exe displays the following error message:

You cannot recover corrupted tasks. To restore the task scheduling features of the system, use SchTasks.exe or Scheduled Tasks to delete the tasks from the system and reschedule them.

schtasks create

Schedules a task.

Schtasks uses different parameter combinations for each schedule type. To see the combined syntax for creating tasks or to see the syntax for creating a task with a particular schedule type, click one of the following options.

Combined syntax and parameter descriptions

Syntax

Parameters

Specifies the schedule type. Valid values are MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE.

MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY

Specifies the time unit for the schedule.

The task runs once at a specified date and time.

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

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

The task runs whenever the system is idle for a specified period of time. You can specify a date, or run the task the next time the system is idle.

Specifies a name for the task. Each task on the system must have a unique name. The name must conform to the rules for file names and must not exceed 238 characters. Use quotation marks to enclose names that include spaces.

Specifies the program or command that the task runs. Type the fully qualified path and file name of an executable file, script file, or batch file. The path name must not exceed 262 characters. If you omit the path, schtasks assumes that the file is in the SystemRoot\System32 directory.

Schedules a task on the specified remote computer. Type the name or IP address of a remote computer (with or without backslashes). The default is the local computer. The /u and /p parameters are valid only when you use /s.

Runs this command with the permissions of the specified user account. The default is the permissions of the current user of the local computer. The /u and /p parameters are valid only for scheduling a task on a remote computer (/s).

The permissions of the specified account are used to schedule the task and to run the task. To run the task with the permissions of a different user, use the **/ruВ **parameter.

The user account must be a member of the Administrators group on the remote computer. Also, the local computer must be in the same domain as the remote computer, or must be in a domain that is trusted by the remote computer domain.

Читайте также:  Konica minolta driver 64 bit windows

Provides the password for the user account specified in the /u parameter. If you use the /u parameter, but omit the /p parameter or the password argument, schtasks prompts you for a password and obscures the text you type.

The /u and /p parameters are valid only for scheduling a task on a remote computer (/s).

Runs the task with permissions of the specified user account. By default, the task runs with the permissions of the current user of the local computer, or with the permission of the user specified by the /u parameter, if one is included. The /ru parameter is valid when scheduling tasks on local or remote computers.

Specifies an alternate user account.

Specifies the local System account, a highly privileged account used by the operating system and system services.

Provides the password for the user account that is specified in the /ru parameter. If you omit this parameter when specifying a user account, SchTasks.exe prompts you for the password and obscures the text you type.

Do not use the /rp parameter for tasks run with System account credentials (/ru System). The System account does not have a password and SchTasks.exe does not prompt for one.

Specifies how often the task runs within its schedule type. This parameter is valid, but optional, for a MINUTE, HOURLY, DAILY, WEEKLY, and MONTHLY schedule. The default value isВ 1.

The task runs every minutes.

The task runs every hours.

The task runs every days.

The task runs every weeks.

The task runs once.

The task runs at startup.

The task runs when the user specified by the /u parameter logs on.

The task runs after the system is idle for the number of minutes specified by the /i parameter, which is required for use with ONIDLE.

The task runs every months.

The task runs on the last day of the month.

FIRST, SECOND, THIRD, FOURTH, LAST

Use with the /d parameter to run a task on a particular week and day. For example, on the third Wednesday of the month.

/d Day[,Day. ] | *

Specifies a day (or days) of the week or a day (or days) of a month. Valid only with a WEEKLY or MONTHLY schedule.

MON — SUN[,MON — SUN. ] | *

Optional. MON is the default. The wildcard value (*) means every day.

FIRST, SECOND, THIRD, FOURTH, LAST

Required for a specific week schedule.

Optional and valid only with no modifier (/mo) parameter (a specific date schedule) or when the /mo is 1 — 12 (an «every В months» schedule). The default is day 1 (the first day of the month).

/m Month[,Month. ]

Specifies a month or months of the year during which the scheduled task should run. Valid values are JAN — DEC and * (every month). The /m parameter is valid only with a MONTHLY schedule. It is required when the LASTDAY modifier is used. Otherwise, it is optional and the default value is * (every month).

Specifies how many minutes the computer is idle before the task starts. A valid value is a whole number from 1 to 999. This parameter is valid only with an ONIDLE schedule, and then it is required.

Specifies the time of day that the task starts (each time it starts) in 24-hour format. The default value is the current time on the local computer. The /st parameter is valid with MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, and ONCE schedules. It is required for a ONCE schedule.

Specifies the repetition interval in minutes. This is not applicable for schedule types: MINUTE, HOURLY, ONSTART, ONLOGON, and ONIDLE. Valid range is 1 to 599940 minutes (599940 minutes = 9999 hours). If either /ET or /DU is specified, then the repetition interval defaults to 10 minutes.

Specifies the time of day that a minute or hourly task schedule ends in 24-hour format. After the specified end time, schtasks does not start the task again until the start time recurs. By default, task schedules have no end time. This parameter is optional and valid only with a MINUTE or HOURLY schedule.

For an example, see:

  • «To schedule a task that runs every 100 minutes during non-business hours» in the To schedule a task that runs everyminutes section.

Specifies a maximum length of time for a minute or hourly schedule in 24-hour format. After the specified time elapses, schtasks does not start the task again until the start time recurs. By default, task schedules have no maximum duration. This parameter is optional and valid only with a MINUTE or HOURLY schedule.

For an example, see:

  • «To schedule a task that runs every 3 hours for 10 hours» in the To schedule a task that runs everyhours section.

Stops the program that the task runs at the time specified by /et or /du. Without /k, schtasks does not start the program again after it reaches the time specified by /et or /du, but it does not stop the program if it is still running. This parameter is optional and valid only with a MINUTE or HOURLY schedule.

For an example, see:

  • «To schedule a task that runs every 100 minutes during non-business hours» in the To schedule a task that runs everyminutes section.

Specifies the date on which the task schedule starts. The default value is the current date on the local computer. The /sd parameter is valid and optional for all schedule types.

The format for StartDate varies with the locale selected for the local computer in Regional and Language Options in Control Panel. Only one format is valid for each locale.

The valid date formats are listed in the following table. Use the format most similar to the format selected for Short date in Regional and Language Options in Control Panel on the local computer.

Use for month-first formats, such as English (United States) and Spanish (Panama).

Use for day-first formats, such as Bulgarian and Dutch (Netherlands).

Use for year-first formats, such as Swedish and French (Canada).

Specifies the date on which the schedule ends. This parameter is optional. It is not valid in a ONCE, ONSTART, ONLOGON, or ONIDLE schedule. By default, schedules have no ending date.

The format for EndDate varies with the locale selected for the local computer in Regional and Language Options in Control Panel. Only one format is valid for each locale.

The valid date formats are listed in the following table. Use the format most similar to the format selected for Short date in Regional and Language Options in Control Panel on the local computer.

Use for month-first formats, such as English (United States) and Spanish (Panama).

Use for day-first formats, such as Bulgarian and Dutch (Netherlands).

Use for year-first formats, such as Swedish and French (Canada).

Specifies to run the task only when the «run as» user (the user account under which the task runs) is logged on to the computer. This parameter has no effect on tasks that run with system permissions.

By default, the «run as» user is the current user of the local computer when the task is scheduled or the account specified by the /u parameter, if one is used. However, if the command includes the /ru parameter, then the «run as» user is the account specified by the /ru parameter.

For examples, see:

«To schedule a task that runs every 70 days if I am logged on» in the To schedule a task that runs every N days section.

«To run a task only when a particular user is logged on» in the To schedule a task that runs with different permissions section.

Specifies to delete the task upon completion of its schedule.

Specifies to create the task and suppress warnings if the specified task already exists.

Displays help at the command prompt.

To schedule a task that runs every N minutes

Minute Schedule Syntax

Remarks

In a minute schedule, the /sc minute parameter is required. The /mo (modifier) parameter is optional and specifies the number of minutes between each run of the task. The default value for /mo is 1 (every minute). The /et (end time) and /du (duration) parameters are optional and can be used with or without the /k (end task) parameter.

Examples

To schedule a task that runs every 20В minutes

The following command schedules a security script, Sec.vbs, to run every 20В minutes. The command uses the /sc parameter to specify a minute schedule and the /mo parameter to specify an interval of 20 minutes.

Because the command does not include a starting date or time, the task starts 20В minutes after the command completes, and runs every 20В minutes thereafter whenever the system is running. Notice that the security script source file is located on a remote computer, but that the task is scheduled and executes on the local computer.

To schedule a task that runs every 100В minutes during non-business hours

The following command schedules a security script, Sec.vbs, to run on the local computer every 100В minutes between 5:00 P.M. and 7:59 A.M. each day. The command uses the /sc parameter to specify a minute schedule and the /mo parameter to specify an interval of 100 minutes. It uses the /st and /et parameters to specify the start time and end time of each day’s schedule. It also uses the /k parameter to stop the script if it is still running at 7:59 A.M. Without /k, schtasks would not start the script after 7:59 A.M., but if the instance started at 6:20 A.M. was still running, it would not stop it.

To schedule a task that runs every N hours

Hourly Schedule Syntax

Remarks

In an hourly schedule, the /sc hourly parameter is required. The /mo (modifier) parameter is optional and specifies the number of hours between each run of the task. The default value for /mo is 1 (every hour). The /k (end task) parameter is optional and can be used with either /et (end at the specified time) or /du (end after the specified interval).

Examples

To schedule a task that runs every five hours

The following command schedules the MyApp program to run every five hours beginning on the first day of MarchВ 2002. 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.

Because the local computer is set to use the English (Zimbabwe) option in Regional and Language Options in Control Panel, the format for the start date is MM/DD/YYYY (03/01/2002).

To schedule a task 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 runs after 12:05В A.M., the program does not run until the next day.

To schedule a task that runs every 3 hours for 10 hours

The following command schedules the MyApp program to run every 3 hours for 10 hours.

The command uses the /sc parameter to specify an hourly schedule and the /mo parameter to specify the interval of 3 hours. It uses the /st parameter to start the schedule at midnight and the /du parameter to end the recurrences after 10 hours. Because the program runs for just a few minutes, the /k parameter, which stops the program if it is still running when the duration expires, is not necessary.

In this example, the task runs at 12:00 A.M., 3:00 A.M., 6:00 A.M., and 9:00 A.M. Because the duration is 10 hours, the task is not run again at 12:00 P.M. Instead, it starts again at 12:00 A.M. the next day.

To schedule a task that runs every N days

Daily Schedule Syntax

Remarks

In a daily schedule, the /sc daily parameter is required. The /mo (modifier) parameter is optional and specifies the number of days between each run of the task. The default value for /mo is 1 (every day).

Examples

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,В 2002. Because it omits the /mo parameter, the default interval ofВ 1 is used to run the command every day.

In this example, because the local computer system is set to the English (United Kingdom) option in Regional and Language Options in Control Panel, the format for the end date is DD/MM/YYYY (31/12/2002)

To schedule a task that runs every 12 days

The following example schedules the MyApp program to run every twelve days at 1:00В P.M. (13:00) beginning on DecemberВ 31,В 2002. The command uses the /mo parameter to specify an interval of twoВ (2)В days and the /sd and /st parameters to specify the date and time.

In this example, because the system is set to the English (Zimbabwe) option in Regional and Language Options in Control Panel, the format for the end date is MM/DD/YYYY (12/31/2002)

Читайте также:  360 total security rus для windows 10

To schedule a task that runs every 70 days if I am logged on

The following command schedules a security script, Sec.vbs, to run every 70В days. The command uses the /mo parameter to specify an interval of 70 days. It also uses the /it parameter to specify that the task runs only when the user under whose account the task runs is logged onto the computer. Because the task will run with the permissions of my user account, then the task will run only when I am logged on.

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 .

To schedule a task that runs every N weeks

Weekly Schedule Syntax

Remarks

In a weekly schedule, the /sc weekly parameter is required. The /mo (modifier) parameter is optional and specifies the number of weeks between each run of the task. The default value for /mo is 1 (every week).

Weekly schedules also have an optional /d parameter to schedule the task to run on specified days of the week, or on all days (*). The default is MON (Monday). The every day (*) option is equivalent to scheduling a daily task.

Examples

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. Because the command omits the /d parameter, the task runs on Mondays.

This command also uses the /s parameter to specify the remote computer and the /u parameter to run the command with the permissions of the user’s Administrator account. Because the /p 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.

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.

To schedule a task that runs every N months

Syntax

Remarks

In this schedule type, the /sc monthly parameter is required. The /mo (modifier) parameter, which specifies the number of months between each run of the task, is optional and the default is 1 (every month). This schedule type also has an optional /d parameter to schedule the task to run on a specified date of the month. The default is 1 (the first day of the month).

Examples

To schedule a task that runs on the first day of every month

The following command schedules the MyApp program to run on the first day of every month. Because a value of 1 is the default for both the /mo (modifier) parameter and the /d (day) parameter, these parameters are omitted from the command.

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.

To schedule a task that runs at midnight on the 21st day of every other month

The following command schedules the MyApp program to run every other month on the 21st day of the month at midnight. The command specifies that this task should run for one year, from July 2, 2002 to June 30, 2003.

The command uses the /mo parameter to specify the monthly interval (every two months), the /d parameter to specify the date, and the /st to specify the time. It also uses the /sd and /ed parameters to specify the start date and end date, respectively. Because the local computer is set to the English (South Africa) option in Regional and Language Options in Control Panel, the dates are specified in the local format, YYYY/MM/DD.

To schedule a task that runs on a specific day of the week

Weekly Schedule Syntax

Remarks

The «day of the week» schedule is a variation of the weekly schedule. In a weekly schedule, the /sc weekly parameter is required. The /mo (modifier) parameter is optional and specifies the number of weeks between each run of the task. The default value for /mo is 1 (every week). The /d parameter, which is optional, schedules the task to run on specified days of the week, or on all days (*). The default is MON (Monday). The every day option (/d *) is equivalent to scheduling a daily task.

Examples

To schedule a task that runs every Wednesday

The following command schedules the MyApp program to run every week on Wednesday. The command uses the /d parameter to specify the day of the week. Because the command omits the /mo parameter, the task runs every week.

To schedule a task that runs every eight weeks on Monday and Friday

The following command schedules a task to run on Monday and Friday of every eighth week. It uses the /d parameter to specify the days and the /mo parameter to specify the eight-week interval.

To schedule a task that runs on a specific week of the month

Specific Week Syntax

Remarks

In this schedule type, the /sc monthly parameter, the /mo (modifier) parameter, and the /d (day) parameter are required. The /mo (modifier) parameter specifies the week on which the task runs. The /d parameter specifies the day of the week. (You can specify only one day of the week for this schedule type.) This schedule also has an optional /m (month) parameter that lets you schedule the task for particular months or every month (*). The default for the /m parameter is every month (*).

Examples

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.

To schedule a task for the first Monday in March and September

The following command schedules the MyApp program to run on the first Monday in March and September. It uses the /mo parameter to specify the first week of the month and the /d parameter to specify the day. It uses /m parameter to specify the month, separating the month arguments with a comma.

To schedule a task that runs on a specific date each month

Specific date syntax

Remarks

In the specific date schedule type, the /sc monthly parameter and the /d (day) parameter are required. The /d parameter specifies a date of the month (1 — 31), not a day of the week. You can specify only one day in the schedule. The /mo (modifier) parameter is not valid with this schedule type.

The /m (month) parameter is optional for this schedule type and the default is every month (*). Schtasks does not let you schedule a task for a date that does not occur in a month specified by the /m parameter. However, if omit the /m parameter, and schedule a task for a date that does not appear in every month, such as the 31st day, then the task does not run in the shorter months. To schedule a task for the last day of the month, use the last day schedule type.

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.

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 P.M. (15:00). It uses the /m parameter to specify the date and the /m parameter to specify the months. It also uses the /st parameter to specify the start time.

To schedule a task that runs on the last day of a month

Last day syntax

Remarks

In the last day schedule type, the /sc monthly parameter, the /mo LASTDAY (modifier) parameter, and the /m (month) parameter are required. The /d (day) parameter is not valid.

Examples

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 and the /m parameter with the wildcard character (*) to indicate that the program runs every month.

To schedule a task at 6:00 P.M. on the last days of February and March

The following command schedules the MyApp program to run on the last day of February and the last day of March at 6:00 P.M. It uses the /mo parameter to specify the last day, the /m parameter to specify the months, and the /st parameter to specify the start time.

To schedule a task that runs once

Syntax

Remarks

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. The /mo (modifier) and /ed (end date) parameters are not valid for this schedule type.

Schtasks does not permit you to 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.

Examples

To schedule a task that runs one time

The following command schedules the MyApp program to run at midnight on JanuaryВ 1,В 2003. It uses the /sc parameter to specify the schedule type and the /sd and st to specify the date and time.

Because the local computer uses the English (United States) option in Regional and Language Options in Control Panel, the format for the start date is MM/DD/YYYY.

To schedule a task that runs every time the system starts

Syntax

Remarks

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.

Examples

To schedule a task that runs when the system starts

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

Because the local computer is uses the English (United States) option in Regional and Language Options in Control Panel, the format for the start date is MM/DD/YYYY.

To schedule a task that runs when a user logs on

Syntax

Remarks

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.

Examples

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.

To schedule a task that runs when the system is idle

Syntax

Remarks

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.

Examples

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.

To schedule a task that runs now

Schtasks does not have a «run now» option, but you can simulate that option by creating a task that runs once and starts in a few minutes.

Syntax

Examples

To schedule a task that runs a few minutes from now.

The following command schedules a task to run once, on November 13, 2002 at 2:18 P.M. local time.

Because the local computer is uses the English (United States) option in Regional and Language Options in Control Panel, 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.

Читайте также:  Windows wireless network configuration

Examples

To run a task with Administrator permissions on the local computer

The following command schedules the MyApp program to run on the local computer. It uses the /ru to specify that the task should run with the permissions of the user’s Administrator account (Admin06). 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.

To run a task with alternate permissions on a remote computer

The following command schedules the MyApp program to run on the Marketing computer every four days.

The command uses the /sc parameter to specify a daily schedule and /mo parameter to specify an interval of four days.

The command 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). It also 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.

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.

To run a task only when a particular user is logged on

The following command schedules 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.

The command 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.

The command 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. It also uses 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.

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 and the /rp parameter is not valid.

Important

The System account does not have interactive logon rights. Users cannot 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.

Note

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.

Examples

To run a task with system permissions

The following command schedules the MyApp program to run on the local computer with permissions of the System account. 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.

The command uses the /ru System parameter to specify the system security context. Because system tasks do not use a password, the /rp parameter is omitted.

In response, SchTasks.exe displays an informational message and a success message. It does not prompt for a password.

To run a task with system permissions on a remote computer

The following command schedules the MyApp program to run on the Finance01 computer every morning at 4:00 A.M. with system permissions.

The command uses the /tn parameter to name the task and the /tr parameter to specify the remote copy of the MyApp program. It uses the /sc parameter to specify a daily schedule, but omits the /mo parameter because 1 (every day) is the default. It uses the /st parameter to specify the start time, which is also the time the task will run each day.

The command 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. It also uses the /ru parameter to specify that the task should run under the System account. Without the /ru parameter, the task would run with the permissions of the account specified by /u.

Schtasks 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.

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. The following procedure demonstrates this method:

Create a batch file that starts the programs you want to run.

In this example, you create a batch file that starts Event Viewer (Eventvwr.exe) and System Monitor (Perfmon.exe).

Open a text editor, such as Notepad.

Type the name and fully qualified path to the executable file for each program. In this case, the file includes the following statements.

Save the file as MyApps.bat.

Use Schtasks.exe to create a task that runs MyApps.bat.

The following command creates the Monitor task, which runs whenever anyone logs on. It uses the /tn parameter to name the task, and the /tr parameter to run MyApps.bat. It uses 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

An Administrator schedules a task on a remote computer

The following command schedules the MyApp program to run on the SRV01 remote computer every ten days starting immediately. The command 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, is not necessary.

Please note that when scheduling tasks on a remote computer, all parameters refer to the remote computer. Therefore, the executable file specified by the /tr parameter refers to the copy of MyApp.exe on the remote computer.

In response, schtasks displays a success message indicating that the task is scheduled.

A user schedules a command on a remote computer (Case 1)

The following command schedules the MyApp program to run on the SRV06 remote computer every three hours. Because Administrator permissions are required to schedule a task, the command uses the /u and /p parameters to provide the credentials of the user’s Administrator account (Admin01 in the Reskits domain). By default, these permissions are also used to run the task. However, because the task does not need Administrator permissions to run, the command includes the /u and /rp parameters to override the default and run the task with permission of the user’s non-Administrator account on the remote computer.

In response, schtasks displays a success message indicating that the task is scheduled.

A user schedules a command on a remote computer (Case 2)

The following command schedules the MyApp program to run on the SRV02 remote computer on the last day of every month. Because the local current user (user03) is not an Administrator of the remote computer, the command uses the /u parameter to provide the credentials of the user’s Administrator account (Admin01 in the Reskits domain). The Administrator account permissions will be used to schedule the task and to run the task.

Because the command did not include the /p (password) parameter, schtasks prompts for the password. Then it displays a success message and, in this case, a warning.

This warning indicates that the remote domain could not authenticate the account specified by the /u parameter. In this case, the remote domain could not authenticate the user account because the local computer is not a member of a domain that the remote computer domain trusts. When this occurs, the task job appears in the list of scheduled tasks, but the task is actually empty and it will not run.

The following display from a verbose query exposes the problem with the task. In the display, note that the value of Next Run Time is Never and that the value of Run As User is Could not be retrieved from the task scheduler database.

Had this computer been a member of the same domain or a trusted domain, the task would have been successfully scheduled and would have run as specified.

Remarks

To run a /create command with the permissions of a different user, use the /u parameter. The /u parameter is valid only for scheduling tasks on remote computers.

To view more schtasks /create examples, type schtasks /create /? at a command prompt.

To schedule a task that runs with permissions of a different user, use the /ru parameter. The /ru parameter is valid for tasks on local and remote computers.

To use the /u parameter, the local computer must be in the same domain as the remote computer or must be in a domain that the remote computer domain trusts. Otherwise, either the task is not created, or the task job is empty and the task does not run.

Schtasks always prompts for a password unless you provide one, even when you schedule a task on the local computer using the current user account. This is normal behavior for schtasks.

Schtasks does not verify program file locations or user account passwords. If you do not enter the correct file location or the correct password for the user account, the task is created, but it does not run. Also, if the password for an account changes or expires, and you do not change the password saved in the task, then the task does not run.

The System account does not have interactive logon rights. Users do not see and cannot interact with programs run with system permissions.

Each task runs only one program. However, you can create a batch file that starts multiple tasks, and then schedule a task that runs the batch file.

You can test a task as soon as you create it. Use the run operation to test the task and then check the SchedLgU.txt file (SystemRoot\SchedLgU.txt) for errors.

schtasks change

Changes one or more of the following properties of a task.

The program that the task runs (/tr).

The user account under which the task runs (/ru).

The password for the user account (/rp).

Adds the interactive-only property to the task (/it).

Оцените статью