Scheduling Application Execution

Windows XP Professional provides administrators with a number of applications that assist in performing administrative tasks. For example, Table 4.2 lists two utilities that perform disk management tasks. As the table shows, these utilities can also be run from the Windows command prompt.

Table 4.2: Windows XP Professional Component Categories

Utility

Command

Description


Disk Cleanup

cleanmgr.exe

Removes unnecessary files from the hard disk

Disk Defragmenter

defrag Consolidates

fragmented files on a disk drive

Note 

More information about the Disk Cleanup and Disk Defragmenter utilities is available in Chapter 11, Disk Management.

The execution of these applications can have a significant impact on the performance of the computer upon which they run. Therefore, it is generally preferable to run these applications during periods when the user is not working on the computer. Using the Windows Task Schedule service, administrators can create tasks and set them up to execute on an automated schedule.

Note 

Windows XP Professional allows only administrators to create and manage scheduled tasks.

Windows XP Professional provides two interfaces for working with the Task Scheduler services. One interface is the AT command. The AT command is a text-based interface used at the Windows command prompt. Using this command, administrators can view, add, and delete tasks. The other interface is the Scheduled Tasks folder. This folder provides a list of currently scheduled tasks, allowing administrators to view, modify, and delete them. The folder also provides access to the Scheduled Task Wizard, which assists in the creation of new scheduled tasks.

The Task Scheduler service allows administrators to schedule the execution of tasks that execute:

  • Daily

  • Weekly

  • Monthly

  • One time only

  • At startup

  • At login

One limitation of scheduled tasks is that they run, by default, using the Local-System user account. This account lacks sufficient permissions to run most tasks. The Scheduled Task Wizard provides the opportunity to specify a user account name and password to be used when executing the script. As long as the user account has the appropriate permissions, the tasks will successfully execute. However, if the user account's password expires and is not updated in the scheduled task, it will fail. One alternative is to create a user account especially for the purpose of running scheduled tasks whose password is very strong (that is, complicated and long) and never expires.

Note 

For instruction on how to create user accounts refer to "Account Management" in Chapter 9, Security Administration.

Configuring the Task Scheduler Service

The Windows XP Task Scheduler service must be configured before it can be used to schedule the automatic execution of tasks. The following procedure outlines the steps involved in configuring the Task Scheduler service.

  1. Click on Start and then Control Panel.

  2. Click on Performance and Maintenance.

  3. Click on Administrative Tools.

  4. Double-click on the Services icon. The Services console opens as shown in Figure 4.11.

    click to expand
    Figure 4.11: Configuring the Task Scheduler service

  5. Scroll down and locate Task Scheduler service. Double-click on it. The Task Scheduler Properties dialog box appears, as shown in Figure 4.12.

    click to expand
    Figure 4.12: The General property sheet on the Task Scheduler Properties dialog can be used to change task startup type and to control task execution

  6. If the service is not started, click on Start.

  7. Make sure that the Startup type drop-down list is set to automatic.

  8. Click on OK.

Scheduling Tasks with the Scheduled Task Wizard

The Scheduled Task Wizard provides a point-and-click tool for creating new scheduled tasks. Its advantage over the AT command is that the administrator does not have to be concerned with remembering command line syntax and is instead guided step by step through new task creation. The following procedure outlines the steps involved in creating a new task using this wizard.

  1. Click on Start and the Control Panel.

  2. Click on Performance and Maintenance.

  3. Click on Scheduled Tasks. The Scheduled Tasks Folder opens, as shown in Figure 4.13.

    click to expand
    Figure 4.13: The Scheduled Tasks folder is the focal point for managing all scheduled tasks

  4. Double-click on the Add Scheduled Task icon. The Scheduled Task Wizard appears.

  5. Click on Next.

  6. A list of Windows XP applications is displayed, as shown in Figure 4.14. Select an application from the list or click on Browse to search for another application.

    click to expand
    Figure 4.14: Select an application to schedule

  7. Type a name for the task and then select one of the available scheduling options, as shown in Figure 4.15.

    click to expand
    Figure 4.15: Select a scheduling option for the new task

  8. If a Daily schedule is selected, the wizard displays the dialog shown in Figure 4.16, allowing further specification of the task's execution schedule. The following options are available:

    click to expand
    Figure 4.16: Setting up a Daily execution schedule

    • Start time. The time at which the task is to begin execution.

    • Perform this task. Choices include running the task daily, just on weekdays or every___days.

    • Start date. The date at which the task is to start executing.

    Click on Next and skip to step 14.

  9. If a Weekly schedule is selected, the wizard displays the dialog shown in Figure 4.17, allowing further specification of the task's execution schedule. The following options are available:

    click to expand
    Figure 4.17: Setting up a Weekly execution schedule

    • Start time. The time at which the task is to begin execution.

    • Every___weeks. Allows task execution on a regular schedule based on a set number of weeks.

    • Select the day(s) of the week below. Allows the specification of the one or more days of the week that the task will run.

    Click on Next and skip to step 14.

  10. If a Monthly schedule is selected, the wizard displays the dialog shown in Figure 4.18, allowing further specification of the task's execution schedule. The following options are available:

    click to expand
    Figure 4.18: Setting up a Monthly execution schedule

    • Start time. The time at which the task is to begin execution.

      Day. The day of the month to run the task.

      The _ _. Specifies the which day of the month to run the task.

      Of the month(s). Specifies the months of the year to run the task.

    Click on Next and skip to step 14.

  11. If a One time only schedule is selected, the wizard displays the dialog shown in Figure 4.19, allowing further specification of the task's execution schedule. The following options are available:

    click to expand
    Figure 4.19: Setting up a One time only execution schedule

    • Start time. The time at which the task is to begin execution.

      Start date. The date at which the task is to start executing.

    Click on Next and skip to step 14.

  12. If a When my computer starts schedule is selected, the wizard displays the dialog shown in Figure 4.20. The following options are available:

    click to expand
    Figure 4.20: Setting up a When my computer starts execution schedule

    • Enter the user name. The name of the user account to be used to execute the task.

    • Enter the password. The password associated with the user account.

    • Confirm password. A confirmation of the password associated with the user account.

    Click on Next and skip to step 14.

  13. If a When I log on schedule is selected, the wizard displays a dialog similar to the one shown in Figure 4.20. The following options are available:

    • Enter the user name. The name of the user account to be used to execute the task.

    • Enter the password. The password associated with the user account.

    • Confirm password. A confirmation of the password associated with the user account.

    Click on Next and skip to step 14.

  14. The wizard displays a dialog similar to the one shown in Figure 4.20. The following options are available:

    • Enter the user name. The name of the user account to be used to execute the task.

    • Enter the password. The password associated with the user account.

    • Confirm password. A confirmation of the password associated with the user account.

    Click on Finish.

Note 

Clicking on Start/All Programs/Accessories/System tools and then selecting Scheduled Tasks will also open the Scheduled Tasks folder.

Once completed, the Scheduled Task Wizard stores the new scheduled task in C:\WINDOWS\TASKS and displays an entry for it in the Scheduled Task folder.

Note 

Any scheduled task can be executed immediately by right-clicking on it and selecting Run.

Most Windows applications are designed to interact with people. For example, the Disk Defragmenter utility will display its graphical user interface when executed as a scheduled task and will not proceed further until it receives instructions. However, many applications, including Disk Defragmenter, support execution from the command line. By using command line syntax to execute the utility, its execution can be fully automated. Unfortunately, while the Scheduled Task Wizard will allow you to browse and find the defrag command, it does not give you the opportunity to specify command line argument. However, command line arguments can be added after the task is created by opening its Properties dialog and typing any required arguments in the Run field on the task property sheet, as demonstrated in Figure 4.21.

click to expand
Figure 4.21: Refining the execution of a scheduled task by adding command line arguments

Note 

For instruction on how to use the DEFRAG command in the Windows XP command line refer to "Performing Disk Maintenance Tasks" in Chapter 11, "Disk Management".

Note 

Administrators can also modify the user account and password used to execute a task, its schedule, and other task settings from its Properties dialog.

In the case of the example shown in Figure 4.21, two arguments have been added to the end of the defrag command, which specify the disk drive to be defragged and that the defrag should run regardless of whether or not the disk drive is heavily fragmented.

Scheduling Tasks with the AT Command

The AT command provides a command line interface for creating, viewing, and managing scheduled tasks. Its advantage over the Scheduled Task Wizard is that it can be incorporated into scripts that can then programmatically control scheduled tasks.

Note 

Information on using scripting as an administrative tool is provided in Chapter 14, Shell Scripting and the WSH.

The following procedure demonstrates the steps involved in opening the Windows command prompt and then creating a new scheduled task.

  1. Click on Start/All Programs/Accessories and then select Command Prompt.

  2. Type AT 00:30 /every:M cmd /c defrag c:/f and press Enter. A message is displayed stating that a new job has been added to the schedule and assigned a numeric job ID, as demonstrated below. In this case a task has been added to the schedule with a job ID = 1 that runs the Disk Defragmenter utility at 30 minutes past midnight every Monday night.

     C:\>at 00:30 /every:M cmd /c defrag d: /f Added a new job with job ID = 1 C:\> 
  3. To view a list of all currently scheduled tasks, type AT and press Enter, as demonstrated below.

     C:\>at Status ID Day Time Command Line ------------------------------------------------------------------         1 Each M 12:30 AM cmd /c defrag d: /f C:\> 

    In this example, one task is currently scheduled to execute.

    Using the AT command you can create scheduled tasks that run on other computers. For example, the following command will set up a task to run on a computer named MyComputer.

     at \\MyComputer /every:M cmd /c defrag d: /f 

    Scheduled tasks can be deleted by specifying their job ID as demonstrated below.

     at 1 /delete 
Note 

Additional information about the AT command can be found in Appendix A, "Windows XP Command Reference."



Microsoft Windows XP Professional Administrator's Guide
Microsoft Windows XP Professional Administrators Guide
ISBN: 1931841969
EAN: 2147483647
Year: 2005
Pages: 358

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net