This should be simple, I need to stop any previous version of my program from running when the installer starts.
Most people suggested making an exe
which does this and calling it before Inno Setup starts. I created an exe
using AutoIt which kills all processes of my program. The problem is I don't know how to get Inno Setup to call it before it installs anything.
How do I call an executable before installing files?
Alternatively, if I can just detect if a program is running and tell the user to close it, that would work too.
Well, I think the easier way to perform this may be creating a DLL in Delphi that detects if your program is running and ask the user to close it, put that DLL in your setup and use the flag "dontcopy" (check in http://www.jrsoftware.org/ishelp/ under Pascal Scripting \ Using DLLs for an example).
Btw, next time use mutexes, Inno Setup also support that and is far more easier.
EDIT: and for extracting a file (if you want to use that .exe you mention), just use ExtractTemporaryFile().
If you're using InnoSetup, you could look into getting your InnoSetup installer to do a Windows SendBroadcastMessage, and get your application to listen for that message. When your application receives the message, it should shut itself down.
I've done this myself with an InnoSetup installer, and it works very well.
I tried using the accepted answer (and the follow up by jachguate) but it wouldn't kill my application. It looks like part of the reason was that my application window had no text associated with it but whatever is the real reason, I used shell command to kill it and that worked. In the [code] section, you want to add the following function. It is called just before setup files are copied.
In version 5.5.0 (Released on May 2012) Inno Setup added support for the Restart Manager API on Windows Vista and newer.
Quote from MSDN linked documentation (emphasis mine):
The good thing is: you don't need to write custom code in the installer or your application to ask the user to close it, or close it automatically.
If you want your application to restart after the update is complete, you have to call the
RegisterApplicationRestart
function from your application first.The default values for the new directives closes all the .exe, .dll and .chm files contained within the
[Files]
section of the installer.The changes related to it are (from release notes):
InnoSetup allows you to attach Pascal scripts to various places in the build process. Try attaching a script that calls ShellExecute. (Which you may have to import to the script engine if it doesn't already have it.)
If the application has a Mutex, you can add an
AppMutex
value in your Inno Setup installer and it will display a message telling the user to stop the program. You might be able to find the Mutex (if it's got one) by using SysInternals Process Explorer and selecting the program / process and looking at the Handles (CTRL-H) in the Lower Pane.Here's a link to the a KB article that mentions several methods:
http://www.vincenzo.net/isxkb/index.php?title=Detect_if_an_application_is_running
Alternatively, you might try this (UNTESTED) code in the
InitializeSetup
: