from Chapter 4, Microsoft Windows 2000 Administrator's Pocket Consultant by William R. Stanek.
When you manage systems, you'll often want to perform tasks like updates or maintenance during nonbusiness hours. This way, you don't affect productivity and workflow. But who wants to come in at 3 a.m. on a Monday morning? Fortunately, using the Task Scheduler service you can schedule one-time or recurring tasks to run automatically at any hour of the day or night.
You automate tasks by running command-shell scripts, Windows Script Host scripts, or applications that execute the necessary commands for you. For example, if you wanted to back up the system drive every weekday at midnight, you could create a script that runs backups for you and records progress and success/failure in a log file.
Utilities for Scheduling Tasks
In Windows 2000, you can schedule tasks on local and remote systems using the Task Scheduler Wizard or the command-line AT scheduler. Each utility has its advantages and disadvantages.
Task Scheduler Wizard provides a point-and-click interface to task assignment. This makes it easy to quickly configure tasks without having to worry about syntax issues. The disadvantage is that you don't have a central location that you can use to check for scheduled tasks throughout the enterprise, and you have to access the wizard separately on each individual system that you want to configure.
The command-line AT scheduler, on the other hand, doesn't have a friendly point-and-click interface. This means you'll have to learn the necessary command syntax and type in commands. The advantage to AT is that you can designate a single server as a task scheduler and you can view and set tasks throughout the enterprise on this single server.
Preparing to Schedule Tasks
Task Scheduler logs on as the LocalSystem account by default. This account usually doesn't have adequate permissions to perform administrative tasks. Because of this, you should configure Task Scheduler to use a specific user account that has adequate user privileges and access rights to run the tasks you want to schedule. You should also make sure that the Task Scheduler service is configured to start automatically on all the systems on which you want to schedule tasks. Set the Task Scheduler startup and logon account as specified in the sections of Chapter 3 entitled "Configuring Service Startup" and "Configuring Service Logon."
A script should configure whatever user settings are necessary. This ensures that everything the script does is under its control and that domain user settings, such as drive mappings, are available as necessary.
Scheduling Tasks with Task Scheduler
You can use Task Scheduler to schedule tasks on the local or remote system to which you're currently connected. You access the Task Scheduler Wizard and currently scheduled tasks through the Scheduled Tasks folder.
Accessing the Scheduled Tasks Folder
You can access the Scheduled Tasks folder on a local system with either of the following techniques:
Start Microsoft Explorer, double-click Control Panel, and then click Scheduled Tasks.
Click Start, click Settings, click Control Panel, and then double-click Scheduled Tasks.
You can access the Scheduled Tasks folder on a remote system by completing the following tasks:
Start Explorer and then use the My Network Places node to navigate to the computer you want to work with.
Double-click the computer's icon and then double-click Scheduled Tasks.
Viewing and Managing Existing Tasks
As Figure 4-10 shows, entries in the Scheduled Tasks folder show currently scheduled tasks. You can work with entries in the Scheduled Tasks folder by completing the following steps:
Double-click Add Scheduled Task to start the Task Scheduler Wizard.
Double-click an existing task entry to view or change its properties. You can set advanced options through the Settings tab.
Select a task entry and press Delete to delete the task.
Creating Tasks with the Task Scheduler Wizard
To schedule a task with the Task Scheduler Wizard, follow these steps:
Start the Task Scheduler Wizard by double-clicking Add Scheduled Task in the Scheduled Tasks folder. Read the welcome dialog box and then click Next.
Using the dialog box shown in Figure 4-11, select a program to schedule. The dialog box shows key applications registered on the system, such as Disk Cleanup and Synchronize. The dialog box doesn't show available scripts, however. Click Browse to open the Select Program To Schedule dialog box. Use the dialog box to find a command-shell or WSH script you want to run.
Figure 4-10: Existing tasks are available in the Scheduled Tasks folder. Click Add Scheduled Task to start the Task Scheduler Wizard.
Figure 4-11: Select a program to run. Click Browse to find scripts and other applications.
Type a name for the task, as shown in Figure 4-12. The name should be short but descriptive so you can quickly determine what the task does.
Select a run schedule for the task. Tasks can be scheduled to run periodically (daily, weekly, or monthly), or when a specific event occurs, such as when the computer starts or when the task's user logs on.
Click Next and then select a date and time to run the scheduled task. The next dialog box you see depends on when the task is scheduled to run.
Figure 4-12: Type a name for the task, and then select a run schedule.
Figure 4-13: Configuring a daily scheduled task.
If you've selected a daily running task, the date and time dialog box appears as shown in Figure 4-13. Set a start time and date. Daily scheduled tasks can be configured to run
Every Day Seven days a week.
Weekdays Monday through Friday only.
Every … Days Every 2, 3, … N days.
If you've selected a weekly running task, the date and time dialog box appears as shown in Figure 4-14. Configure the task using these fields:
Start Time Sets the start time of the task.
Every … Weeks Allows you to run the task every week, every 2 weeks, or every N weeks.
Figure 4-14: Configuring a weekly scheduled task.
Figure 4-15: Configuring a monthly scheduled task.
- Select The Day(s) Of The Week Below Sets the day(s) of the week when the task runs, such as on Monday or on Monday and Friday.
If you've selected a monthly running task, the date and time dialog box appears as shown in Figure 4-15. Configure the task using these fields:
Start Time Sets the start time of the task.
Day Sets the day of the month the task runs. For example, if you select 5, the task runs on the fifth day of the month.
The … Day Sets task to run on the Nth occurrence of a day in a month, such as the second Monday or the third Tuesday of every month.
Of The Month(s) These check boxes let you select which months the task runs on.
If you've selected One Time Only for running the task, the date and time dialog box appears as shown in Figure 4-16. Set the start time and start date.
With tasks that run when the computer starts or when the task's user logs on, you don't have to set the start date and time. The task runs automatically when the startup or logon event occurs.
Tip If you want to configure a startup task for a specific user through the wizard, you'll need to log on as that user and then run the wizard.
After you've configured a start date and time, click Next to continue. Then type a username and password that can be used when running the scheduled task. This username must have appropriate permissions and privileges to run the scheduled task.
Figure 4-16: Configuring a one time only scheduled task.
The final wizard dialog box provides a summary of the task you're scheduling. Click Finish to complete the scheduling process. If an error occurs when you create the task, you'll see an error prompt. Click OK. The task should still be created. Afterward, in Explorer double-click the task to correct the problem in the related properties dialog box.
Scheduling Tasks with the At Utility
You can also control the Windows 2000 Task Scheduler service with the At utility. With At you can schedule tasks anywhere on the network and you don't have to log on to remote systems. You can set tasks to run once or periodically at a specific time.
Using the At Utility
To schedule tasks with At, you should be a member of the local Administrators group. Tasks are scheduled using a 24-hour clock where 12:00 is noon and 00:00 is midnight. The At utility doesn't automatically load the command interpreter before running built-in command-line utilities, such as DEL, COPY, or MOVE. You'll need to explicitly load cmd.exe at the beginning of a command. For example, if you wanted to copy c:\mydata\*.* to e:\backups\mydata, you would need to enter the following command:
AT 00:00 /every:M,T,W,Th,F "cmd /c copy /Q c:\mydata\*.* e:\backups\mydata"
When you work with programs and utilities that have separate executables, you don't have to start an instance of the command interpreter. You can work with the executable directly. Still, the executable must be in a directory accessible along the command path (the %PATH% environment variable). Here's how you could schedule a backup script to run every other day at 1 a.m.:
AT 01:00 /every:1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 backup.js
As you can see, when you use numeric dates you can use any value in the range 1–31. You schedule tasks to run relative to the current date as well. To do this, specify only a start time and not a run date. For example, to start a cleanup script at 3 a.m., you could use the following command:
AT 03:00 cleanup.js
You can also schedule tasks to run on the next occurrence of a day. For example, if today is Tuesday and you want the task to run on Friday, you could use the following command:
AT 08:10 /next:F update.vbs
Normally, scheduled tasks run as background processes. You can, however, set tasks to run interactively. To do this, use the /interactive switch, such as:
AT 03:00 /interactive /every:T,Th backup.vbs
Scheduling Tasks on Remote Systems
The AT command makes it easy to schedule tasks to run on remote systems. Simply type the UNC name of the computer before you specify other parameters. For example, if you wanted to schedule a task to run on a computer called PLUTO, you could type the following command at the command line on your system:
AT \\PLUTO 08:10 /next:F update.vbs
You could also use the Internet Protocol (IP) address of the computer, such as:
AT \\22.214.171.124 09:30 /every:M,W,F cleanup.js
Only use this option if the IP address is static.
Scheduling tasks on remote systems assumes that
You've configured the Task Scheduler service on PLUTO to use a logon with appropriate permissions.
The Task Scheduler service is running.
The scripts are located in directories that can be found along the path set for the service logon account.
Viewing Scheduled Tasks
You can view scheduled tasks on local and remote systems. On a local system, type AT on a line by itself and press Enter.
On a remote system, type AT followed by the UNC name of the system you want to examine:
When you view tasks, the output you get is similar to the following:
Status ID Day Time Command Line 1 Each M W F 3:00 AM backup.vbs 2 Each T Th 5:00 AM cleanup.js 3 Each Su 8:00 AM update.js
The output tells you a lot about the scheduled tasks. You can determine
Status Shows the status of each task. A blank entry indicates a status of OK. Otherwise, you'll see an error message, such as ERROR.
ID Shows the unique identifier for each task.
Day Shows when the task is scheduled to run. Recurring tasks begin with the keyword Each, such as Each M for every Monday. One-time tasks begin with the keyword Next, such as Next 3 for the next time it's the third day of the month.
Time Shows the time the command is scheduled to run. Note that the time is displayed with an a.m. or p.m. indicator rather than the 24-hour clock used for scheduling tasks.
Command Line Shows the command or executable run at the scheduled time.
You can use the status ID to display individual tasks, such as:
AT \\zeta 2
You can use the ID number to delete tasks as well, or you can cancel all scheduled tasks. You delete a specific task as follows:
AT 2 /delete
AT \\zeta 2 /delete
You cancel all tasks by typing the /delete switch without a task ID, such as:
AT \\zeta /delete
from Microsoft Windows 2000 Administrator's Pocket Consultant by William R. Stanek. Copyright © 1999 Microsoft Corporation.