Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
To run a program or script at a specified time on a specified date, you must create a scheduled task that contains the following information:
Scheduled tasks can be created on local computers by using the Scheduled Task Wizard. However, this wizard cannot be used to schedule tasks on remote computers (or to simultaneously schedule tasks on more than one computer). If you need to create scheduled tasks on remote or multiple computers, you can use the command-line tool At.exe or create a custom script by using the WMI class Win32_ScheduledJob.
The Win32_ScheduledJob Create method can be used to create scheduled tasks on a computer. The Create method requires the parameters shown in Table 17.14. Parameters not required for a specific task should be left blank.
Table 17.14 Win32_ScheduledJob Properties Available to the Create Method
Property | Description |
---|---|
Command | Name of the executable program, batch file, or script to be run. |
StartTime | UTC time to run the job. This is of the form YYYYMMDDHHMMSS.MMMMMM(+ )OOO, where YYYYMMDD must be replaced by ********. Example: ********123000.000000 420, which implies 12:30 P.M. Pacific time with daylight saving time in effect. |
RunRepeatedly | Indicates whether the scheduled job should run repeatedly on the days that the job is scheduled. The default is FALSE. This parameter is optional. |
DaysOfWeek | Days of the week when the task should be run. Values are: 1 Monday 2 Tuesday 4 Wednesday 8 Thursday 16 Friday 32 Saturday 64 Sunday To run the task on multiple days, use a logical OR to combine values. For example, to run a task on Tuesday, Thursday, and Saturday, use the following code:
To run a task on multiple days, you must set the RunRepeatedly parameter to True. |
DaysOfMonth | Days of the month when the job is scheduled to run; used only when the RunRepeatedly parameter is True. This parameter is optional. |
InteractWithDesktop | Indicates whether the specified job should be interactive (meaning that a user can give input to the scheduled job while it is executing). The default is False. This parameter is optional and is rarely set to True. In general, the reason to use a scheduled task is to allow a task to be carried out without any user interaction. |
JobID | Identifier number of the job. This parameter is a handle to the job being scheduled on this computer. |
When a scheduled task is created, one of the error codes shown in Table 17.15 is returned, indicating the success or failure of the procedure.
Table 17.15 Win32_ScheduledJob Error Codes
Error Code | Description |
---|---|
0 | The scheduled task was successfully created. |
1 | The request is not supported. |
2 | The user did not have the necessary access. |
8 | Interactive Process. |
9 | The directory path to the service executable file was not found. |
21 | Invalid parameters have been passed to the service. |
22 | The account under which this service is to run either is invalid or lacks the permissions to run the service. |
Listing 17.30 contains a script that schedules a task on a computer. To carry out this task, the script must perform the following steps:
This constant will be used to indicate that the scheduled task should run repeatedly. If set to False, the scheduled task will run once and then never run again.
These constants represent the days of the week when the script is scheduled to run.
In this example, the file is Monitor.exe.
The constant RUN_REPEATEDLY, with the value True, means that the job should run repeatedly.
The constants MONDAY, WEDNESDAY, and FRIDAY indicate the days of the week when the task should run.
This parameter is left blank because the job is scheduled to run on specific days of the week.
This parameter is left blank because the task does not need to interact with the user.
Listing 17.30 Scheduling a Task
|
|
Send us your feedback | « Previous | Next » |