7. Managing Tasks
Task Scheduler
simplifies task management and monitoring. This section explains how to
view task history, export tasks, and import tasks.
Display Running Tasks
To display all tasks currently running on the
system, open Task Scheduler and select Display All Running Tasks from
the Action menu. This opens the All Running Tasks window, and you can
click Refresh to manually refresh the display. You can also select one
or more tasks and click End Task to stop tasks on demand.
Viewing History
The History tab of a task displays all the
known events for that task and allows you to quickly see the last time
the task ran and its status. Only events that relate to the currently
selected task will be shown, eliminating the need to scour the Task
Scheduler event log for individual events from specific tasks.
To view the history of a task, do the following:
1. | If Task Scheduler is not open, start Task Scheduler.
|
2. | Find and click the task folder in the console tree that contains the task you want to view.
|
3. | In the console window, click the task that you want to view.
|
4. | Click
the History tab to view the task’s history. Click an event, in the list
of events on the History tab, to view the description of the event.
|
Exporting Tasks
You can export tasks to an .xml file and then
import them at some later time, on either the same computer or a
different computer. This feature allows for easy portability of tasks
from computer to computer.
To export a task, follow these steps:
1. | Right-click the task that you want to export and then select Export, or select Export in the Action pane.
|
2. | Browse to where you want to save the file, enter the name of the file, and then click Save.
|
3. | The task will be saved in .xml format. The following example shows a simple task.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2006-04-11T13:54:51</Date>
<Author>USER1-VISTA\user1</Author>
<Description>Test Task</Description>
</RegistrationInfo>
<Triggers>
<TimeTrigger id="1a08ebe4-0527-4e7a-af76-84f2ef1dbfa0">
<StartBoundary>2006-04-11T13:55:23</StartBoundary>
<Enabled>true</Enabled>
</TimeTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>USER1-VISTA\user1</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\calc.exe</Command>
</Exec>
</Actions>
</Task>
|
Importing Tasks
Tasks that have been exported can also be easily imported to another computer or the same computer.
To import a task, follow these steps:
1. | Right-click
a task folder under the Task Scheduler Library and select then Import
Task, or select Import Task in the Action pane.
|
2. | Browse
to where the .xml file is located and click Open. The task will be
automatically imported into the library using the settings contained in
the .xml file.
|
Note
To ensure that the task runs properly, it is recommended that you verify the properties of the task after you import it. |
Using the SchTasks.exe Command
This section describes the SchTasks.exe
command-line syntax and parameters. The Schtasks.exe command-line
interface utility allows an administrator to create, delete, query,
change, run, and end scheduled tasks on a local or remote system through
the command shell.
Command Syntax
The SchTasks.exe command interface uses the following syntax:
schtasks /<parameter> [arguments]
Command Parameters
/Create Creates a new scheduled task
/Delete Deletes the scheduled task(s)
/Query Displays all scheduled tasks
/Change Changes the properties of scheduled task
/Run Runs the scheduled task immediately
/End Stops the currently running scheduled task
/? Displays this help message
Creating Tasks
The general syntax for Schtasks.exe is as follows:
SCHTASKS
/Create [/S system [/U <username> [/P [<password>]]]] [/RU
<username> [/RP <password]] /SC schedule [/MO <modifier>]
[/D <day>] [/M <months>] [/I <idletime>] /TN
<taskname> /TR <taskrun> [/ST <starttime>] [/RI
<interval>] [ {/ET <endtime> | /DU <duration>} [/K]
[/XML <xmlfile>] [/V1]] [/SD <startdate>] [/ED
<enddate>] [/IT] [/Z] [/F]
Example command:
SCHTASKS /Create /S system /U user /P password /RU runasuser /RP runaspassword
/SC HOURLY /TN rtest1 /TR notepad
Deleting Tasks
Syntax:
SCHTASKS /Delete [/S <system> [/U <username> [/P [<password>]]]] /TN <taskname> [/F]
Example command:
SCHTASKS /Delete /TN "Backup and Restore"
Running Tasks
Syntax:
SCHTASKS /Run [/S <system> [/U <username> [/P [<password>]]]] /TN <taskname>
Example command:
SCHTASKS /Run /TN "Start Backup"
Ending Tasks
Syntax:
SCHTASKS /End [/S <system> [/U <username> [/P [<password>]]]] /TN <taskname>
Example command:
SCHTASKS /End /TN "Start Backup"
Querying Tasks
Syntax:
SCHTASKS /Query [/S <system> [/U <username> [/P [<password>]]]] [/FO <format>] [/NH] [/V] [/?]
Example commands:
SCHTASKS /Query /S system /U user /P password
SCHTASKS /Query /FO LIST /V
Changing Tasks
Syntax:
SCHTASKS
/Change [/S <system> [/U <username> [/P
[<password>]]]] /TN <taskname> { [/RU <runasuser>]
[/RP <runaspassword>] [/TR <taskrun>] [/ST
<starttime>] [/RI <interval>] [ {/ET <endtime> | /DU
<duration>} [/K]] [/SD <startdate>] [/ED <enddate>]
[/ENABLE | /DISABLE] [/IT] [/Z] }
Example command:
SCHTASKS /Change /RP password /TN "Backup and Restore"