1. General information
- Scheduled tasks are programs that run in the background of the Windows operating system. Scheduled tasks are configured in the “Task Scheduler”.
- The purpose of scheduled tasks is to periodically run executable programs
- once a day, weekly or monthly at a given time (hour and minute) – for example at 04:00 in the morning,
- every day repeatedly from a given time (hour and minute) in a given interval (number of hours/minutes) and for a given time (number of hours) – for example from 06:00 in the morning in an interval of 30 minutes for 18 hours,
- or in any combination and using restrictions on specific days – for example
- every Monday, Wednesday and Friday at 22:00,
- on the first of January, March and June at 08:00 in the morning,
- etc.
1.1. Scripts on buttons (Button controls)
- NET Genium uses scheduled tasks to periodically run scripts, defined within buttons located on view pages.
- For simpler and more user-friendly scheduling of tasks, Setup.exe can be used, allowing task scheduling without directly modifying system settings.
- Run Setup.exe from the bin directory.
- Select the option to schedule a task for RunScript.exe, which appears among the last options in the interface.
- Enter the button ID of the script you want to schedule.
- Set the time and frequency for running the script and confirm by clicking “Setup”.
- The “RunScript.exe” program, located in the “bin” directory of each NET Genium, is used to run the script defined by the button.
- Use: “RunScript.exe <ID> [<UserID>]”
- The “ID” parameter means the ID of the button, and it can be found in admin mode in the tooltip that appears after stopping the mouse pointer over the link “Modify Button ID ...” or over the link “Modify script”.
- The program always runs the steps of the button script – regardless of whether the “Run script” option is checked and of the command type set in the “Server” field. The program does not perform the button command itself (for example opening an edit form or a view page, or printing to a template).
- The optional “UserID” parameter represents the ID of the user under whose login name the script will run. If the optional parameter is not specified, the script will run under an anonymous user, and print templates printed by the script are then generated regardless of access rights. With the parameter specified, the rights of the given user apply. If no user with the specified ID exists (for example after the user has been deleted) or the value is not a number, the program does not run the script. Print templates are generated the same way in the scripts that the script starts with the “SCHEDULESCRIPT” server function.
- The “SCHEDULEPRINT” and “SCHEDULEPRINTOFATTACHMENT” server functions are not executed when the script is run by “RunScript.exe”, not even in the scripts run by the “SCHEDULESCRIPT” server function. The “SCHEDULEFORM”, “SCHEDULEVIEWPAGE”, “SCHEDULEURL”, “SCHEDULEBACK”, “SCHEDULEENTRY”, “SCHEDULEPORTLETS” and “SCHEDULEMAILMESSAGE” functions, which schedule navigation after the script completes, have no effect either. A print template can be printed into an attachment in the script by the “PRINTATTACHMENT” server function.
Details
- The button script runs in one database transaction, which is committed only when the script completes successfully. The “COMMIT()” server function commits it in the middle of the script and begins a new one. Scripts run by the “SCHEDULESCRIPT” server function run only after the button script has been committed, each in its own transaction. If one of them ends with an error, the remaining scripts scheduled by the same script are no longer run, but the writes of the button script and of the scheduled scripts completed earlier remain saved. However, an e-mail sent by the “Send email” step is sent immediately, so a later error of the script does not take it back. The “Config\Demo.txt” file prevents the script steps from writing to the database, sending e-mails from the script and executing most server functions that write to the database, to attachments or to the disk, for example “DELETEDATA”, “DELETEHISTORY”, “CREATEATTACHMENT” or “LOGSERVICE”, and “COMMIT()” is not executed either. However, external functions called from the script run normally, with the “test” parameter set to “false”, and can write to the database.
- The program returns exit code 0 on successful completion and 1 on an error – also when the button script does not exist or is empty, when the ID does not belong to a button on a view page, when no user with the specified “UserID” exists, or when a script run by the “SCHEDULESCRIPT” server function fails. The details of the error are in the “Errors” log. The program also returns exit code 1 without running the script if NET Genium is deactivated (the “Config\UnderConstruction.txt” file) or is being updated – in such a case it writes the reason to the “Warnings” log. Run without parameters, it only displays its usage and returns 1 without writing to a log.
- A chat message to a single user that the script sends with the “SENDCHATMESSAGE” server function with the “loginname” parameter does not always trigger a notification on a mobile phone or a computer after 30 seconds – the notification for it is sent only after any signed-in user has the portal open in a window that is visible, the NET Genium web application sends another chat message to a single user or a group, or it starts again, and only if the message has stayed unread until then and is not older than 24 hours.
- Using a scheduled task, it is not possible to directly run scripts defined within the buttons located in edit forms. However, this limitation can be easily solved by launching a button on the view page, which then launches a button located in the edit form using the server function “SCHEDULESCRIPT(int button, int id)”.
Details
- The ID entered into “Setup.exe” as well as into “RunScript.exe” is always looked up among the controls of view pages. “Setup.exe” therefore rejects the ID of an edit form button and “RunScript.exe” ends with exit code 1 – but if the ID matches the ID of a button on a view page, “Setup.exe” schedules and “RunScript.exe” runs that view page button. The task created by “Setup.exe” is named after the button found, so its name can be used to verify that the correct button is scheduled.
1.2. Service tools
- NET Genium also uses scheduled tasks to periodically run service tools:
- Backing up databases and files using “BackupServer.exe”
- Backing up databases using “SqlBackup.exe”
- Backing up file attachments with “FileBackup.exe”
- Automatically update NET Genium to the latest version using “Update.exe”
- Periodically sending failed emails from the “SMTP” directory using the “ResendEmlFiles.exe” program
- Regularly cleaning up the log tables and log files using “SqlBackup.exe” with the “/deletelogs” parameter
- Sending the database table synchronization queue using “StartSynchro.exe”, if the web application does not send it by itself
- A detailed description of the service tools is provided in the separate guide Utilities.
2. Creating scheduled tasks with “Setup.exe” program
- “Setup.exe” is the recommended method for creating scheduled tasks associated with the execution of button scripts located on view pages. Scheduled tasks created by the “Setup.exe” program can also be manually configured directly in the “Task Scheduler”.
- All scheduled tasks are created in the “NET Genium” folder, which either already exists or is created by “Setup.exe”.
- Scheduled tasks are set to run in the context of the user account “SYSTEM” with the highest privileges.
- Run the “Setup.exe” program located in the “bin” directory of each NET Genium.

- Check the options you want to choose as described below:
- “Create scheduled task for BackupServer.exe (server backup)”
- Check this option if you want to automatically create a scheduled task for regular backups of the server – database and directory.
- “Create scheduled task for SqlBackup.exe (database backup)”
- Check this option if you want to automatically create a scheduled task for regular database backups.
- The task gets the database from the “ConnectionString.txt” file in the “Config” directory as its argument and no backup target. The “SqlBackup.exe” program therefore saves the backup to the “Backup” directory of the NET Genium installation every day into a new file “yyyy-mm-dd-database_name” and does not delete older backups. If the number of backups is to be limited, a space and a backup target with a variable, for example #dayofweek#, must be added in the “Task Scheduler” to the “Add arguments” field after the database. A detailed description of the parameters of the “SqlBackup.exe” program is provided in the separate guide Database backup and restore.
- “Create scheduled task for FileBackup.exe (attachments backup)”
- Check this option if you want to automatically create a scheduled task for regularly backing up file attachments. The task is created without the target backup directory, which is mandatory for the “FileBackup.exe” program – the target directory must be added to the “Add arguments” field in the “Task Scheduler”, otherwise the task ends with an error.
- “Create scheduled task for Update.exe (update)”
- Check this option if you want to automatically create a scheduled task for regularly updating NET Genium to a new version.
- “Create scheduled task for ResendEmlFiles.exe”
- Check this option if you want to automatically create a scheduled task to periodically send failed emails from the “SMTP” directory.
- “Create scheduled task for RunScript.exe”
- Check this option if you want to automatically create a scheduled task to run the script with the given ID, at a specified time, or with the possibility of repeating the task regularly 2x per hour for 18 hours.
- The task gets only the button ID as its argument, so the script runs under the anonymous user. If it is to run under a specific user, the user ID must be added in the “Task Scheduler” to the “Add arguments” field after the button ID and a space.
- The start time is entered in the “hh:mm” format, the default value is “06:00”. A value without a colon is evaluated as 00:00.
- The created tasks run daily – “BackupServer”, “BackupDatabase” (the “SqlBackup.exe” program) and “BackupAttachments” (the “FileBackup.exe” program) at 00:05, “Update” at 04:00, “ResendEmlFiles” from 06:00 repeatedly every 30 minutes for 18 hours, and the task for “RunScript.exe”, named after the button, at the specified time.
- Click the “Setup” button to start the installation. After a successful completion the program closes. In case of an error its window remains open. It displays a message only on an error or a warning – it warns for a task that it has not changed because it already exists, and with an MSSQL database for each created or changed task that its user account must be changed to an account with access to the database.
Details
- “Setup.exe” looks up an existing scheduled task by its name in the “NET Genium” folder. If a task of the same name has an action that runs the same program (the file at the same path), “Setup.exe” does not change it, reports that the task already exists, and neither the new start time nor the new arguments apply. In such a case the task must be modified directly in the “Task Scheduler”. A task of the same name without such an action, typically a task of another NET Genium installation on the same computer, gets an additional action and keeps its original start time.
- The task for “RunScript.exe” is named after the button. For a second button with the same name, “Setup.exe” therefore does not create the task and reports that it already exists – the button must be renamed, or the task must be created manually in the “Task Scheduler”.
- Run the “Task Scheduler” and check the created scheduled task, or change the user account in the context of which the scheduled task should be executed.
- An additional user account change is necessary especially in situations where we plan to run a program with access to the database – “FileBackup.exe”, “Update.exe”, “ResendEmlFiles.exe” and “RunScript.exe” – and when the database server is installed on computer other than the application itself, or IIS. In this case, it is not possible to use the default user account “SYSTEM”, but typically a dedicated service account defined in “Active Directory”.
- Database backups are generally only possible from a computer that is also a database server. Therefore, it makes sense to run the “BackupServer.exe” and “SqlBackup.exe” programs only from a computer that is also a database server.