As you know, you normally start programs by double-clicking icons or issuing commands from the command line. But what if you want programs to start themselves? You can use the Windows 2000 Task Scheduler. In this Daily Feature, we’ll look at Task Scheduler and use it to schedule a disk cleanup.
What is Task Scheduler?
This scheduler is a great advancement over the Windows NT command prompt scheduler or the WinAT scheduler. When you install Windows 2000, Task Scheduler is automatically installed.
Using Task Scheduler, you can schedule any script, program, or document to run at a time that’s most convenient for you. Task Scheduler starts each time you start Windows 2000 and runs in the background. You can use Task Scheduler to modify an existing task, to stop a scheduled task, to view a log of past scheduled tasks, or to view tasks that are scheduled on a remote computer. You can send and receive task files in e-mail messages, and you can share the Scheduled Tasks folder on your computer so that you can access it remotely through My Network Places.
Task Scheduler allows you to schedule any application to run. Windows 2000 employs an easy-to-use wizard that will guide you through the scheduling process step-by-step.
Before we look at the actual scheduler, let’s look at the things that must be in place in order for it to work. You must first verify that the Task Scheduler service is running. Then, you must determine that the date and time on the computer on which you’re scheduling a task are correct. If the time, date, or time zone settings are incorrect, your scheduled task may start at an inopportune time.
Running Task Scheduler
Running Task Scheduler is pretty easy because Microsoft has created a wizard to help you. The example we’ll look at in this Daily Feature will show how to schedule a disk cleanup. To open Task Scheduler, navigate to Control Panel and click Task Scheduler. You’ll be presented with an icon named Add Scheduled Task, as shown in Figure A.
|Start the Scheduled Task Wizard by double-clicking the Add Scheduled Task icon.|
Tasks that you have already scheduled will appear here also. When you double-click the Add Scheduled Task icon, the Scheduled Task Wizard will start. Click Next to bypass the first screen.
Next, the wizard displays a list of tasks you can automate. To choose one, simply scroll through the list and highlight the task, as shown in Figure B. If the desired task is not listed, you can click Browse and find the application or batch file of your choice.
|You can select the task to schedule here.|
For our example, we’re going to schedule the Disk Cleanup task, so choose that task and click Next to continue. At this point, you name the task and choose when it is to run, as shown in Figure C.
|Windows 2000 gives you a wide range of choices of how often to run tasks.|
With the Windows 2000 Task Scheduler, you have choices that the Windows NT Task Scheduler didn’t have. You can run a task one time only, when the computer starts, or when you log on to the computer. In our example, we will choose to run the task weekly and then click Next to continue.
At this point, you set the start time and days of the week for the task to run. Depending on the task to be scheduled, you must have sufficient rights in order to perform it. Select the times you want the task to run and click Next.
On the next screen, enter a username and password for the task to use if it needs to log on to the server. The task will run as if that user had logged in to the system personally and started the task. The task’s user ID can be different from that of the user who is currently logged in to the system. Enter the user ID and password and then click Next to continue.
In Windows 2000, tasks are scheduled and performed based on standard Windows 2000 security permissions. You can configure tasks by using the NTFS file system security descriptors to set permissions for those users or groups who can view, delete, modify, or use a task. In addition, the items that make up the task are controlled by whatever security descriptors are present for those individual items. Once a username and password are set, another user cannot cancel or delete the task unless that user has the proper permissions. This will prevent a task from failing due to insufficient rights.
If a task such as the Disk Cleanup utility has options of its own that can be set, you can reach these options by selecting the Open Advanced Properties For This Task When I Click Finish check box, as shown in Figure D.
|You can set additional options by selecting Open Advanced Properties For This Task When I Click Finish.|
If you do select this check box, when you click Next, the Advanced properties page appears. The Settings tab, shown in Figure E, allows you to configure the task even further. You can choose to terminate the task if it takes longer than a specific time to run, to start the task only if the computer has been idle for a specific amount of time, to stop the task if the computer ceases to be idle, to not start the task if the computer is on battery power, or to stop the task if battery mode begins. You can also choose to wake your computer to run a task if the computer starts running on battery power.
|The Advanced properties page allows you to set additional options for the task.|
Once you have configured and scheduled a task, it will appear in the Scheduled Tasks list.
The AT command
Windows NT employed the AT command to schedule commands, scripts, or programs. In Windows 2000, the AT command works with Task Scheduler, which provides additional functionality. If you have created a task using the AT command, the task will be listed in the Scheduled Tasks folder with a name such as At3478.
You can view or modify the task, but if you decide to modify the task, it will be upgraded to a Windows 2000 scheduled task. At that point, the task is no longer visible to the AT command, and the AT account setting no longer applies to it. You will have to explicitly enter a user account and password for the task.
All tasks that you create using the AT command must run in the same user account. You can configure this account to be the local system account or any user account by modifying the Schedule service; click the Services icon in Control Panel to modify a service. In Windows 2000, each task created from the Scheduled Tasks folder can run in a different account.
Windows 2000 requires the Schedule service to run in the local system account. Use the Advanced menu in the Scheduled Tasks folder to set an account other than the local system account to hold tasks created by the AT command.
Some tasks may not run exactly as you had expected. When this happens, right-click the task and choose Properties. Then, check the following settings to determine the source of the problem:
- On the Task tab, make sure that the Enabled check box is selected.
- On the Schedule tab, make sure that the task is scheduled correctly.
You may also need to add command-line options to the path of the program. Depending on the program you’re scheduling, you may be able to view online help by typing the program name followed by /? at the command prompt.
The Status column in the Scheduled Tasks window shows the current status of the task. Additional information about the status of a task can be found in the log file named SchedLog.txt, which is stored in the \WinNT folder. The SchedLog.txt file records the activity of a scheduled task and may help you determine why it failed.
You must also ensure that the Task Scheduler service has been started and that the user has sufficient permissions to execute the task. If a user is not logged in to a computer that can use his or her account to run a task, the task will run but will not be visible.
The Windows 2000 Task Scheduler can help you run recurring tasks easily. The Task Scheduler Wizard makes scheduling such a breeze that you will forget anything you ever learned about the Windows NT 4.0 AT scheduling command.
The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.