hometriangle-righttriangle-leftmenu3

Setting Up a Scheduled Task

When setting up a scheduled task on the server, a lot of problems can arise from misconfiguration.

The most reliable method we have found to setup these tasks are as follows:

  • Make sure that the scheduled task is run whether the user is logged in or not.
  • If a scheduled task is executing a VB Script (vbs) file, make sure that the following config is set so the MS Access database driver is using the 32bit version and not the 64bit:
    Program/script: C:/windows/syswow64/cscript.exe
    Arguments: "C:/file/path/to/script.vbs"
    Start in: C:/windows/syswow64/
  • The task should run no longer than 8 hours
  • If the task is already running, then it should close the existing instance.

Tracking Schedule Task Errors

Tracking schedule task errors should be done 2 ways.

1) As part of the weekly maintenance, the assigned user should check the Scheduled Task log for any errors and email Gerry with the details.

2) Create a special scheduled task to track script errors, script timeouts or other errors that will automatically send an email to dev@ or support@.

To setup this scheduled task, follow these steps:

There should be 5 triggers, 1 trigger for every Event Id that corresponds to a scheduled task problem. The event Id's are as follows:

  • 203 - Failed to Start
  • 103 - Action start failed
  • 323 - Current instance stopped
  • 135 - Launch conditions not met
  • 329 - Task stopping due to timeout reached

To setup a trigger, goto the trigger tab.

Begin the task: On an event
Log: Microsoft-Windows-TaskScheduler/Operational/
Source: TaskScheduler
Event ID: <insert single event Id>

Once the triggers have been setup, the next step is to setup the system that will create the error log file. This file will be attached to the email and will contain the appropriate error information.

To setup the log file:

Create 2 folders on the server e.g. /scripts/ & /scripts/tmp/ and create a .cmd file that contains the following code:

del C:\Scripts\tmp\ScheduledTask-LastError.txt
wevtutil qe Microsoft-Windows-TaskScheduler/Operational "/q:*[System[(EventID=203) or (EventID=103) or (EventID=323) or (EventID=135) or (EventID=329)]]" /f:text /rd:true /c:1 > C:\Scripts\tmp\ScheduledTask-LastError.txt

Once this is done, we can then create 2 actions in the schedule task, 1 to create the log file and 1 to send the email.

  • Create one action that points to the C:\Scripts\tmp\ScheduledTask-LastError.cmd
  • Create a second action that sends an email to dev@ or support@. The attachment should reference the written log file: C:\Scripts\tmp\ScheduledTask-LastError.txt

That's it!