20

I have a small console application that is installed along my (bigger) application. The setup is created with Inno Setup, which works very nice.

I want Inno Setup to add one or more tasks to the windows scheduler (that starts the console app). Is there a way to do that?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
real_yggdrasil
  • 1,213
  • 4
  • 14
  • 27

2 Answers2

20

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.

TLama
  • 75,147
  • 17
  • 214
  • 392
  • 6
    Thank you very much TLama! I didn't know it would be that simple. This is the line i added to the Inno script: [Run] Filename: schtasks.exe; Parameters:" /create /tn "ESS pushdata" /tr {app}\pushdata.exe /sc daily " – real_yggdrasil Sep 03 '12 at 15:08
14

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992