3

I have an exe file that I've created using pyinstaller. I am using Inno Setup to create a Windows installer for this executable.

Here's a snippet from my compiler script :

Filename: "schtasks"; \
  Parameters: "/Create /F /SC MINUTE /MO 2 /TN ""Discovery"" /TR ""'{app}\Discovery.exe'"""; \
  Flags: runhidden runminimized

I'm using schtasks to schedule the execution of my exe file (Discovery.exe). The scheduling works perfectly fine but a command line window still appears when the file runs. This leads me to believe that there's something weird happening with runminimized and runhidden

Discovery.exe is in fact a command line application created using pyinstaller.

How do I ensure that no command line window shows up when this file is supposed to run?


Final working [Run] statement on Inno Setup based on the answer by @Bill_Stewart:

[Run]
Filename: "schtasks"; \
  Parameters: "/Create /F /SC MINUTE /MO 5 /TN ""Discovery"" /TR ""'wscript.exe' '{app}\RunHidden.js' '{app}\Discovery.exe' "" "; \
  Flags: runhidden runminimized;

Note the usage of quotations due to spaces in my file paths.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
jaimish11
  • 536
  • 4
  • 15

1 Answers1

2

The problem is that the runhidden flag in Inno Setup's [Run] section is running the schtasks command, and the schtasks command is scheduling your program (Discovery.exe) to run. When the package installs, the schtasks command runs hidden as requested, but this doesn't mean that the scheduled task you are creating will run Discovery.exe as a hidden process.

If you are running the scheduled task as the current user, the Task Scheduler doesn't have a "run this task hidden" setting. However, you can work around this by creating a short WSH script:

// RunHidden.js
// Runs a program in a hidden window
// Run this script using wscript.exe

var Args = WScript.Arguments;

if ( (Args.Unnamed.Count == 0) || (Args.Named.Item(0) == "/?") ) {
  WScript.Echo('Usage: wscript RunHidden.js "command"');
  WScript.Quit(0);
}

var FSO = new ActiveXObject("Scripting.FileSystemObject");
var Command = Args.Unnamed.Item(0);
if ( ! FSO.FileExists(Command) ) {
  WScript.Echo("File not found - " + Command);
  WScript.Quit(2);  // ERROR_FILE_NOT_FOUND
}

var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run('"' + Command + '"',0);

You can distribute the above script with your installation. Schedule wscript.exe as the program to run, the above script and Discovery.exe as parameters, and the scheduled task should run the command without a window.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62