How to add a scheduled task with Inno Setup

Simply add the task scheduler command line entries to the [Run] section of your script. The entries in that section are executed after the program is successfully installed.


To give a more concrete example than the @TLama's answer:

For example, to schedule a task to run your application with some parameter every hour, use:

[Run]
Filename: "schtasks"; \
    Parameters: "/Create /F /SC HOURLY /TN ""My Task"" /TR ""'{app}\MyProg.exe' par1"""; \
    Flags: runhidden

Note:

  • the double double-quotes around the command-line (and task name) and single quotes around the path to the application;
  • the /F switch to overwrite any existing task with the same name (important for re-installations/upgrades).

See a full documentation for the schtasks.exe command and the [Run] section.


When you want to debug a non-working task creation, start the schtasks with the cmd.exe /K (and of course, remove the runhidden flag):

[Run]
Filename: "{cmd}"; \
    Parameters: "/K schtasks /F /Create /SC HOURLY /TN ""My Task"" /TR ""'{app}\MyProg.exe' par1"""; 

This way the console window with an error message is preserved.

See Debugging non-working batch file or command executed from Inno Setup installer.


For uninstalling, see Delete Task Scheduler task at Uninstall?

Tags:

Inno Setup