APGen Documentation Previous Topic: Executing APG Scripts from the Command Line Next Topic: Programmatic Execution Parent Topic: Executing APG Scripts    Executing APG Scripts
Scheduled Execution of APG Scripts
See Also:

APG scripts can be executed on a scheduled basis using the at command or using the Windows 2000 Task Scheduler.  The Schedule service must be running to use either scheduler.

Both schedulers require you to specify a command line to execute.  For more information on command line syntax, see Executing APG Scripts from the Command Line.

The at Command

The at command is available in Windows NT and Windows 2000.  It supports scheduling a task to run at a specific time and date(s).  Type at at the Command Prompt to see a list of scheduled tasks.  Type at /? at the Command Prompt for syntax help.

This example batch file (schedule_morning_news.bat) uses the at command to schedule dailynews.apg to run at 8am every morning:

echo off
echo ************************************************
echo *  Scheduling daily execution of dailynews.apg *
echo ************************************************


REM Set the path of the APG script
Set ScriptPath="D:\news\apg\dailynews.apg"


REM Schedule dailynews.apg - no debugging
at 8:00 /interactive /every:M,T,W,Th,F,S,Su %ScriptPath% /s /nd


REM Test for success.
If errorlevel 1 goto SchedulingErrorOccurred
  
REM If we're here, scheduling was successful
Echo *** %ScriptPath% scheduled for execution every day at 8am. ***
Goto Done
    
REM Report the error, then exit
:SchedulingErrorOccurred
   Echo *** Error %errorlevel% occurred while scheduling %ScriptPath%. ***
   Goto Done

:Done

Once this batch file is executed, dailynews.apg will be executed at 8am every morning.

A real dailynews.apg page would probably extract recent news articles or postings from a database.  This example APG script does not display any real news, but does show a headline and the date the page was generated:

<%# @LANGUAGE="VBScript" #%>
<%# '---------------- dailynews.apg ----------------

' Figure out the time string
Dim dtNow, sToday
dtNow = Now
sToday = WeekdayName(Weekday(dtNow)) & ", " & FormatDateTime(dtNow, vbShortDate)

#%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Daily News -
<%# =sToday #%></TITLE></HEAD>
<BODY>
<%#
' Normally daily news would be queried from a database
#%>
<H2>Daily News for
<%# =sToday #%></H2>
<hr>
<p>News item 1</p>
<hr>
<p>News item 2</p>
<hr>
Copyright &copy; 2001, WebGecko<br>
<div style="font-size:xx-small">Generated at
<%# =dtNow #%></div>

</BODY></HTML>

The Task Scheduler

The Task Scheduler is available in Windows 2000.  It provides a graphical user interface, and a superset of the features of the at command.  The "Scheduled Tasks" folder in Windows Explorer provides convenient access to the scheduled tasks on a computer.

The Task Scheduler provides much functionality that is not available using the at command.  For example, using the Task Scheduler, it is easy to execute an APG script every hour from 8am to 5pm on weekdays:

When you schedule a task using the at command, the task is listed in the Scheduled Tasks folder using a name like at xx, where xx is a number.  You can then view or modify the task.  If you modify it, it is upgraded to a normal scheduled task, and is no longer visible to the at command.  You will need to explicitly enter a user account and password for upgraded tasks.

Security Considerations

The Schedule service is a Windows service, and the considerations discussed in the Security topic apply.  The primary concerns are whether the user account executing the APG script has the privileges required to run the script, and whether the account has the privileges required to write the output file.

In the Task Scheduler, you can set the user account that each task runs in.

The user account used for writing output files and log files can be set programmatically using the APGen.Logon, Output.Logon, and Log.Logon objects.