Schtasks

From Wikipedia, the free encyclopedia

In computing, schtasks (schtasks.exe) is a command which schedules other commands to be run at a certain time. It may run a command once, or repeatedly based upon the day of the week, or the date. It is available on all Windows NT-based operating systems produced after Windows 2000 (NT 5.0) with the exception of Windows XP Home and Starter Editions.

Each command is given a Security Identifier (SID) which is assigned at the time of the task's creation. The SID is a Unique ID which is long enough to ensure no duplicates will occur. All unfinished or repeating jobs are reloaded at boot time, with the same SIDs unlike at jobs which use sequential numbering, and can change at boot-time.

Scheduled tasks are not run if the computer is turned off at the time, or is in sleep mode or in hibernation. The Scheduler service must also be running.

Usage

By itself, schtasks gives a list of all pending jobs. By using /query and additional options more details of specific tasks are displayed.

To shut down a computer at 10:00 in the evening:

schtasks /Create /TN Shutdown /ST 22:00 /TR "shutdown -s"

The above example will cause a scheduled task to be created named 'Shutdown' which will cause shutdown.exe to shut down the computer the next time the computer's clock reads 10pm. Note unlike 'at' the time must be given in HH:mm (24 hour time). Also note that shutdown.exe is in one of the folders (normally C:\Windows\System32) listed in the %PATH% environment variable. Other commands will require the full file path.)

Commands can also be scheduled on other computers on a local-area network, using a remote procedure call (RPC). However, the user must be an administrator, have permission on the other machine, and the user account on both machines must have a password (RPC will refuse if passwords are blank). The UNC computer name is placed immediately after schtasks /Create using /S ComputerName, and must be followed by /U Username and /P Password in order to do this, as follows:

 schtasks /Create /S \\OtherComputer /U RemoteUser /P RemotePassword /TN Shutdown /ST 22:00 /TR "shutdown -s"

The shutdown command is then scheduled on the remote computer named "OtherComputer" (not locally), and will show in its list of jobs. A remote computer's jobs can also be checked as follows:

schtasks /S \\OtherComputer

Flags

Several Base flags greatly expand the usefulness of schtasks All Base flags come before the command being scheduled. However after a base flag is given there are often additional flags which can be used before or after the task name.

Base Flag /Create has many associated sub flags some of which are shown below:

The /SC Flag Specifies the schedule frequency. Valid schedule types: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT can be used to repeat a command at the same event occurrence, such as time of day, day of the week, week of the month or year, month of the year, log on, log off, or other system event.

The /MO Flag Refines the schedule type to allow finer control over schedule recurrence. But relies on further codes such as /D to allow for this

The /D Flag Specifies the day of the week to run the task. Valid values: MON, TUE, WED, THU, FRI, SAT, SUN and for MONTHLY schedules 1 - 31 (days of the month). Wildcard "*" specifies all days.


schtasks /Create /TN Shutdown /SC WEEKLY /MO /D MON, TUE, WED, THU, FRI /ST 22:00 /TR "shutdown -s"
schtasks /Create /TN Shutdown /SC WEEKLY /MO /D SAT, SUN /ST 19:00 /TR "shutdown -s"

The above commands will shut down the computer at 10:00 PM (22:00) every weekday evening, and at 7:00 PM (19:00) every weekend evening.

The Full List of Base flags is shown below: Support Microsoft

The /? Flag Shows the general help screen when no other flags are specified, shows help listing all additional sub flags when used after a base flag

For example:
schtasks /? Shows What Base Flags are
schtasks /Run /? Shows What sub-flags apply to the /Run flag.

The /Run Flag Runs a previously scheduled command.

The /End Flag Stops a scheduled command which is already executing.

The /Create Flag Creates a new scheduled command.

The /Delete Flag Deletes a scheduled command.

The /Query Flag Lists scheduled command information.

The /Change Flag Changes the parameters of an existing scheduled command.

The /ShowSid Flag Will list the SID of a given command, must be used in conjunction with the /TN Flag.

Replacement

Prior to Windows XP, and Windows 2003 server, the at was used to schedule commands via the command line; although this command is not as powerful or flexible, it is far simpler to use, and still functions under later versions of Windows NT. The Task Scheduler is the graphical user interface to schtasks, and at jobs will show in the task lists of both programs.

See also

References


This article is issued from Wikipedia. The text is available under the Creative Commons Attribution/Share Alike; additional terms may apply for the media files.