Task Scheduler Using VBScript
Task Scheduler Using VBScript
aIntroduction
bHow it Works
cThe Components
Provided by:
Todd Weber
Microsoft Consulting Services
Task Scheduler through a VBScript, scheduling agent dll and a configuration file, solves the ever present
problem of providing a consistent, repeatable method to schedule tasks.
You can get started now by scheduling your system state backups through the sample provided by this handy
utility.
Schedule System State Backups - Fast
1. Download TaskScheduler.exe to your computer.
2. Extract the contents of the executable file to any drive on your computer, for example, c:\scheduler.
Modify the tasks.xml file
a. change the user line to <your domain>\<username>
b. change the password
c. save the changes
3. Start Windows Explorer.
4. Navigate to c:\scheduler.
5. Double click the inst_task.cmd file.
Click here to copy TaskScheduler.exe to your computer
Introduction toptop
A frequently overlooked area of application development and deployment is the necessity to schedule the same task
or group of tasks repeatedly on the same or different computers. The jobs are typically scheduled via a repetitive
manual process, which often times prone to mistakes. Mistyping a character in a parameter string or not following
exactly the same process each time the information is entered can lead to unexpected results.
Scheduling packages come in all shapes and sizes. A scheduling package usually provides the data movement
backbone of an application system, driving data loads or automatic report generation. Cleanup tasks, backups and
other housekeeping type chores vital for a systems stable performance are also done via a scheduling package. For a
variety of reasons, the different jobs that are run often exist in several scheduling packages. The gestalt is a mess to
set up and administer. What is needed is an easy to use method that will allow for the repetitive scheduling of tasks
on different systems under different scheduling packages.
The Task Scheduling solution provides the ability to repetitively schedule task for any scheduling package provided
that the scheduling package has a COM interface.
The process of scheduling applications is driven by a VBScript which takes as an input parameter the xml based
configuration file. The configuration file contains generic settings such as output directory and specific settings such
as the tasks to schedule. The script performs a series of pre-processing steps eventually instantiating and calling the
scheduling agent specified in the configuration file. The scheduling agent, really just a wrapper on the scheduler's
API, does the actual work of scheduling the task. Processing status, including errors, are logged to file in the
directory specified in the configuration file on the root directory of the computer.
Process Flowchart
VBScript
The VBScript is the main driver for the task scheduling system. The script performs most of its work setting up the
environment for the actual scheduling of the tasks. The general process flow for the script can be seen in the
VBScript PseudoCode.
One of the first tasks performed by the script is to validate that the passed parameters are indeed valid. Currently the
script takes only one passed parameter, which it assumes is the configuration file. The input filename is retrieved
from the passed parameters and read and loaded into the document object model.
The next set of steps is used to create the output directory and log file. The output directory is stored location is
found in the configuration file, loaded in the set of steps above. The script reads the information found in the
document object model and will recursively create the directory structure specified if it does not already exist. The
log file is then created.
The final step sets up and performs the true task of the system, the scheduling of tasks. Scheduling the tasks is
performed by looping through the tasks node list retrieved and loaded earlier in the process. Each task has an
associated scheduling agent, which is instantiated and called from the VBScript. The agent if not already installed
and registered is done so in the program step that schedules the task. The scheduling agent is then called, passing in
the parameter information retrieved from the configuration file.
VBScript PseudoCode
1. Check to see if the passed arguments meet requirements
2. Get the input file
3. Load the document object model
4. Determine the output directory
5. Create the output directory
6. Create the log file
7. Schedule the tasks
Scheduling Agent
The scheduling agent is a thin wrapper for the individual scheduling server's API. The scheduling agent implements
a standard scheduling interface (ISchedule). Each scheduling server supported provides a wrapper which is
implemented with the ISchedule interface. The interface has one publicly exposed method, ScheduleTask which
takes as its parameters the task name, application to be run, parameters for the application, user id, password, start
date for the task and the start time.
The scheduling agent takes the information passed and schedules the task by calling the API for the implemented
scheduling agent. In the example provided, the scheduling agent used is NT's task scheduler.
Configuration File
The configuration file contains information used for all tasks, such as the output directory, and the information
necessary to schedule the specific task. XML is used as the format for the configuration file. The file is divided into
two primary sections, constants and tasks. The constants section contains configuration information used by the
VBScript. Data in this area is in the name/value pair combinations. In the example provided, the first and only
constant, "output" has the value of "task". Task Scheduler script uses this parameter to determine the location of the
output directory.
Tasks is the second and final section of the configuration file. Tasks contains listing of individual tasks to be
scheduled. Each task has the following information: scheduling agent, dll, name, application, parameters, user,
password, starttime, startdate. The scheduling agent entry represents the prog id used by the VBScript to instantiate
and call the ScheduleTask method. DLL represents the dll which houses the implementation. The other parameters
are passed to the ScheduleTask method.