Scheduling the Running of Scripts

Microsoft® Windows® 2000 Scripting Guide

Tasks that you script often need to be done repeatedly according to a prescribed schedule. You can use the Windows 2000 Task Scheduler or At.exe to schedule the running of these scripts. The scripts still run under one of the script hosts, but they run at the designated times without your interaction.

The ability to run scripts without the need for any human intervention is one of the major advantages scripting has over other administrative tools. For example, suppose you have a script that runs once a week and backs up and clears the event logs on all your domain controllers. There is no need for you to remember to manually run this script each week, and no need for you to arrange for someone else to run this script should you be out of the office. Instead, the script can be scheduled to run once a week, and it can do so without any need for human intervention. As an added bonus, the script can be scheduled to run during off-hours, thus minimizing any disruption to users.

You can also use WMI to create, delete, and manage scheduled tasks. (For more information about scheduling the running of scripts using WMI, see "Creating Enterprise Scripts" in this book.) For example, this script creates a scheduled task that runs a script named Monitor.vbs every Monday, Wednesday, and Friday at 12:30 P.M.

Set Service = GetObject("winmgmts:")
Set objNewJob = Service.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
    ("cscript c:\scripts\monitor.vbs", "********123000.000000-420", _
        True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated