Subscribe to Windows IT Pro
February 12, 2002 12:00 AM

Scripting Solutions with WSH and COM: Scheduling Automated Tasks

Windows IT Pro
InstantDoc ID #23935
Rating: (0)
Downloads
23935.zip

Customizing an Existing Task
After you've created a task, you can access that task's properties by right-clicking it in the Task Scheduler GUI, then selecting Properties. The properties dialog box has three tabs—Task, Schedule, and Settings. The Task tab, which Figure 3 shows, provides summary information for the task in question. On the Schedule tab, which Figure 4, page 14, shows, notice the Show multiple schedules check box. Selecting this check box lets you set values for different schedules. For example, you could run the same task at 2:00 a.m., 4:30 a.m., and 10:30 p.m. every weekday, then at 9:30 a.m. on Saturdays and Sundays. The Settings tab, which Figure 5, page 14, shows, has the bulk of useful task settings, such as whether to run the task while something else is running (i.e., the machine isn't idle), whether to run the task on a laptop that's running on battery power, how long to let the task run before forcibly terminating it, and whether to delete the task after it has run.

Note that customizing an AT task upgrades it to a normally scheduled task, thereby removing the task from AT's management. In such a case, you need to explicitly enter a user account and password for the task.

Task Administration
Deleting and renaming tasks is as simple as right-clicking the task in the GUI and selecting the appropriate option. You can also run a task at any time or end a running task in this way.

A few other control functions are available from the Advanced menu in the GUI. For example, you can stop and start the Task Scheduler service, pause Task Scheduler while you do something else, request to be notified of failed tasks (if you're an administrator), and look at the task log (by default, C:\windows\schedlgu.txt).

One other administrative option relates to AT and bears a bit of explaining. You've seen that each task that you create through the wizard can run under a different account. However, all tasks that you create with the At command must run in the same user account, which in turn has to be the same account that the Schedule service in earlier Windows versions ran in. The default account was the Local System account, but you can use any user account. In XP, the Task Scheduler service has to run under the Local System account. However, you can designate an account other than Local System for tasks that you create with the At command to run in. To do so, click the Advanced menu in the Scheduled Tasks GUI, then select AT Service Account.

Using Tasks in Your Systems Administration
Rather than schedule all the tasks yourself, you can send tasks to users for them to schedule. To move tasks from your PC to the users' PCs, you simply drag the tasks from the Scheduled Tasks GUI into your C:\windows\tasks folder, then email the tasks to the users and instruct them to drag the tasks into this folder. However, two more common ways exist for moving tasks between machines. First, you can share the Tasks folder on each PC. Second, and the choice I opt for, you can set up a central server share structure (e.g., using XP's or Win2K's Dfs so that it's fault tolerant) that holds all your tasks, then you can have a task on each PC that updates its set of tasks from that share.

Let's look at the latter option. Let's assume that you have four departments (Finance, HR, Development, and Sales), each of which has a PC and a separate set of scripts. To share the Tasks folder on each department's PC, create a folder on SERVER1 (server1.mycorp.com) called Tasks. Beneath Tasks, create four folders corresponding to the four departments. Then, share the Tasks root folder and everything below it under the name Tasks. Use the code that Listing 4 shows—FinanceCopyTasks.cmd—as the scheduled task on all Finance machines. For the other departments, use the same script with the word Finance in the line

\\server1.mycorp.com\tasks\finance\

replaced with the appropriate department name. The /v, /y, and /z switches correspond to requests to verify copied files, overwrite as needed without prompting, and restart across the network if the connection is lost, respectively.

Next Time
Next time, I'll show you how to use Active Directory Service Interfaces (ADSI) to make FinanceCopyTasks.cmd much better. For now, try experimenting with Scheduled Tasks to automate other systems administration tasks, such as automated user-creation. (For a particularly useful demonstration of task-scheduling functionality, see Tim Huckaby's Windows Web Solutions article "Sending Email from IIS," March 2002, InstantDoc ID 23811.)

Related Content:

ARTICLE TOOLS

Comments
  • Brad Maiorino
    10 years ago
    May 10, 2002

    Thanks for this great article on using Task Scheduler to distribute jobs to remote machines. There is one major drawback that you don't address and I was hoping you could help me overcome it. After I copy the *.job files to the remote computer, the account the job was originally setup with gets reset. Do you know how to get around this? I don't see how this can work without it.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.