As a software developer, I love Inno Setup! It is a wonderful, powerful, free software-deployment tool. I’ve tweaked my programs’ Inno Setup scripts to accomplish certain important, but tricky tasks.
Inno Setup: How to close a program before reinstalling it
Most recently, I looked for a way to check if a program is running (and to close that program) when we’re about to install a new version. I found an existing script which checks to see if a program is running and exits the installation if it is (after first displaying an error message in a message box.) It was very helpful in presenting the basic concept. However, I wanted the script to give the user the opportunity of closing the target program and continuing with the installation, rather than aborting the whole process. The resulting, expanded script accomplishes this. It includes documentation and groups basic customization options close together, so you can easily adapt the script for your own installers.
- Inno Setup Kill Process Before Install Average ratng: 3,7/5 7101 votes End a process with Inno setup. 2018//02/22 - Dallas. These two functions will ctry to close the process gt4t.exe at installation and uninstallation.
- 32 bit installer refuses to run on 64 bit Windows. 64 bit installer refuses to run on 32 bit Windows. Dependencies (such as Visual C runtime and.NET Framework) are packed. Platform dependent library files are put in different folders (x64 or x86). Version Comparison. The version comparison code has been updated slightly in the two installer.
Inno Setup Kill Process Before Install Windows 10
Inno Setup is a free installer for Windows programs by Jordan Russell and Martijn Laan. First introduced in 1997, Inno Setup today rivals and even surpasses many commercial installers in feature set and stability. Features Learn more about what Inno Setup can do. Download Inno Setup Get the latest version of Inno Setup here. Mailing List.
To test the script’s resulting installer, open up a Notepad window and leave it open before running the installer (or uninstaller.)
You’ll need the following resources to compile this script:
- PSVince (the DLL with the function to determine if a given application is running)
- the script (a.k.a. “Prompt to Close the Program”, which you can download or copy-and-paste from the text below)
You can also download a compiled, executable version to see it in action before deciding whether to adapt it for your own needs.
— Andrés Cabezas
;——————————————————————————-
; This sample script was created by Andres Cabezas ( http://wwww.domador.net )
; It is based on another sample script, created by Vincenzo Giordano, found at
; http://www.vincenzo.net/isxkb/index.php?title=Call_psvince.dll_on_install_and_uninstall
; http://www.vincenzo.net/isxkb/index.php?title=Call_psvince.dll_on_install_and_uninstall
; To clarify your freedom to use this code, I’ve appended a license at the end,
; an even-more-permissive version of the already-permissive Expat license.
; an even-more-permissive version of the already-permissive Expat license.
;——————————————————————————-
; Sample application-name settings
[Setup]AppName=Prompt to Close the ProgramAppVersion=1.0
DisableProgramGroupPage=true
DisableStartupPrompt=true
DefaultDirName={pf}Prompt to Close the Program
DefaultGroupName=”Prompt to Close the Program”
OutputBaseFilename=PromptToCloseTheProgramSetup
;——————————————————————————-
[Files]; DLL used to check if the target program is running at install timeSource: psvince.dll; flags: dontcopy
![Inno setup documentation Inno setup documentation](https://images.sftcdn.net/images/t_app-cover-m,f_auto/p/16accf72-96db-11e6-bf8a-00163ec9f5fa/313576495/inno-setup-313576495.jpg)
; uninstall time to check if the target program is running
Source: psvince.dll; DestDir: {app}
; Comment out the following two lines if you don’t want a Start Menu program group
; to be created. (You’ll need to run the uninstaller’s EXE directly from its
; folder (e.g. “C:Program FilesPrompt to Close the Program”) if you do.)
[Icons]Name: “{group}Uninstall this application”; Filename: “{uninstallexe}”
; to be created. (You’ll need to run the uninstaller’s EXE directly from its
; folder (e.g. “C:Program FilesPrompt to Close the Program”) if you do.)
;——————————————————————————-
[Code]
////////// Customize the following constants to suit your own program //////////
const
// Name of the application that should be closed and name of its executable
ProgramName = ‘Notepad’;
ProgramExeName = ‘notepad.exe’;
ProgramExeName = ‘notepad.exe’;
// Messages user will see if the application is running.
// (It may be a good idea to give instructions on HOW to close your application,
// if it’s not obvious to the user (e.g., in the case of background applications)
// (It may be a good idea to give instructions on HOW to close your application,
// if it’s not obvious to the user (e.g., in the case of background applications)
ProgramRunningOnInstallMessage = ProgramName + ‘ is currently running. ‘ + #13 + #13 +
‘Please close it and then click on ”Retry” to proceed with the installation.’;
InstallationCanceledMessage = ‘The installation was canceled.’;
‘Please close it and then click on ”Retry” to proceed with the installation.’;
InstallationCanceledMessage = ‘The installation was canceled.’;
ProgramRunningOnUninstallMessage = ProgramName + ‘ is currently running. ‘ + #13 + #13 +
‘Please close it and then click on ”Retry” to proceed.’;
UninstallationCanceledMessage = ‘The uninstallation process was canceled.’;
‘Please close it and then click on ”Retry” to proceed.’;
UninstallationCanceledMessage = ‘The uninstallation process was canceled.’;
////////////////////// end of basic-customization section //////////////////////
//——————————————————————————
// IsModuleLoadedI – function to call at install time
// Also added setuponly flag
function IsModuleLoadedI(modulename: String ): Boolean;
external ‘IsModuleLoaded@files:psvince.dll stdcall setuponly’;
// Also added setuponly flag
function IsModuleLoadedI(modulename: String ): Boolean;
external ‘IsModuleLoaded@files:psvince.dll stdcall setuponly’;
// IsModuleLoadedU – function to call at uninstall time
// Also added uninstallonly flag
function IsModuleLoadedU(modulename: String ): Boolean;
external ‘IsModuleLoaded@{app}psvince.dll stdcall uninstallonly’ ;
// Also added uninstallonly flag
function IsModuleLoadedU(modulename: String ): Boolean;
external ‘IsModuleLoaded@{app}psvince.dll stdcall uninstallonly’ ;
//——————————————————————————
// Calls IsModuleLoadedI or IsModuleLoadedU as appropriate
function IsModuleLoaded( modulename: String; isUninstallation: Boolean ): Boolean;
begin
if isUninstallation then
Result := IsModuleLoadedU( modulename )
else
Result := IsModuleLoadedI( modulename );
end;
begin
if isUninstallation then
Result := IsModuleLoadedU( modulename )
else
Result := IsModuleLoadedI( modulename );
end;
//——————————————————————————
// Prompt the user to close a program that’s still running.
// Finish when the executable is closed or the user cancels the process.
// Finish when the executable is closed or the user cancels the process.
Inno Setup Kill Process Before Install A House
// -> message : A message to show the user to prompt them to close
// -> isUninstallation : Whether this is an uninstallation (to call the right function.)
// <- True if the program was closed (or was not running),
// False if the user clicked on the Cancel button and didn’t close the program
// -> isUninstallation : Whether this is an uninstallation (to call the right function.)
// <- True if the program was closed (or was not running),
// False if the user clicked on the Cancel button and didn’t close the program
function PromptUntilProgramClosedOrInstallationCanceled(
message: String;
isUninstallation: Boolean ): Boolean;
var
ButtonPressed : Integer;
begin
ButtonPressed := IDRETRY;
message: String;
isUninstallation: Boolean ): Boolean;
var
ButtonPressed : Integer;
begin
ButtonPressed := IDRETRY;
// Check if the program is running or if the user has pressed the cancel button
while IsModuleLoaded( ProgramExeName, isUninstallation ) and ( ButtonPressed <> IDCANCEL ) do
begin
ButtonPressed := MsgBox( message , mbError, MB_RETRYCANCEL );
end;
while IsModuleLoaded( ProgramExeName, isUninstallation ) and ( ButtonPressed <> IDCANCEL ) do
begin
ButtonPressed := MsgBox( message , mbError, MB_RETRYCANCEL );
end;
// Has the program been closed?
Result := Not IsModuleLoaded( ProgramExeName, isUninstallation );
end;
Result := Not IsModuleLoaded( ProgramExeName, isUninstallation );
end;
//——————————————————————————
function InitializeSetup(): Boolean;
begin
Result := PromptUntilProgramClosedOrInstallationCanceled( ProgramRunningOnInstallMessage, False );
begin
Result := PromptUntilProgramClosedOrInstallationCanceled( ProgramRunningOnInstallMessage, False );
if Not Result then
begin
MsgBox( InstallationCanceledMessage, mbInformation, MB_OK );
end;
end;
begin
MsgBox( InstallationCanceledMessage, mbInformation, MB_OK );
end;
end;
//——————————————————————————
function InitializeUninstall(): Boolean;
begin
Result := PromptUntilProgramClosedOrInstallationCanceled( ProgramRunningOnUninstallMessage, True );
begin
Result := PromptUntilProgramClosedOrInstallationCanceled( ProgramRunningOnUninstallMessage, True );
// Unload the DLL, otherwise the dll psvince is not deleted
UnloadDLL(ExpandConstant(‘{app}psvince.dll’));
UnloadDLL(ExpandConstant(‘{app}psvince.dll’));
if not Result then
begin
MsgBox( UninstallationCanceledMessage, mbInformation, MB_OK );
end;
end;
begin
MsgBox( UninstallationCanceledMessage, mbInformation, MB_OK );
end;
end;
//——————————————————————————
// Copyright (C) 2011 by Andres Cabezas Ulate ( [email protected] )
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//——————————————————————————
In this chapter, we will walk you through the process of creating an executable and then packaging it up into an installer. We will be using a really neat little user interface called GUI2Exe that was written by Andrea Gavana to create the executable. It is based on wxPython, so you will need to have that installed to use it. GUI2Exe supports py2exe, bbfreeze, cx_Freeze, PyInstaller and py2app. Then once we have the dist folder created, we will use Inno Setup to create our installer.
We will be using the following code once more:
Let’s get started!
Getting Started with GUI2Exe¶
To use GUI2Exe, you just have to go to its website (http://code.google.com/p/gui2exe/) and download a release. Then you unzip it and run the script that’s called GUI2Exe.py. The GUI2Exe project is based on wxPython, so make sure you have that installed as well. I ran mine successfully with wxPython 2.9. Here’s how you would call it:
![Inno Inno](https://i1.wp.com/fernandofreitasalves.com/wp-content/uploads/2015/03/assistente-inno-setup-3.jpg)
If that executed successfully, you should see a screen similar to this one:
Now go to File -> New Project and give your project a name. In this case, I called the project wxForm. If you want to, you can add a fake Company Name, Copyright and give it a Program Name. Be sure to also browse for your main Python script (i.e. sampleApp.py). According to Andrea’s website, you should set Optimize to 2, Compressed to 2 and Bundled Files to 1. This seems to work most of the time, but I’ve had some screwy errors that seem to stem from setting the last one to 1. In fact, according to one of my contacts on the py2exe mailing list, the bundle option should be set to 3 to minimize errors. The nice thing about setting bundle to “1” is that you end up with just one file, but since I’m going to roll it up with Inno I’m going to go with option 3 to make sure my program works well.
Once you have everything the way you want it, click the Compile button in the lower right-hand corner. This will create all the files you want to distribute in the dist folder unless you have changed the name by checking the dist checkbox and editing the subsequent textbox. When it’s done compiling, GUI2Exe will ask you if you want to test your executable. Go ahead and hit Yes. If you receive any errors about missing modules, you can add them in the Python Modules or Python Packages section as appropriate. For this example, you shouldn’t have that issue though.
Now we’re ready to learn about creating the installer!
Let’s Make an Installer!¶
Now that we have an executable and a bunch of dependencies, how do we make an installer? For this chapter we’ll be using Inno Setup, but you could also use NSIS or a Microsoft branded installer. You will need to go to their website (http://www.jrsoftware.org/isdl.php), download the program and install it. Then run the program. You should see the main program along with the following dialog on top of it:
Choose the Create a new script using the Script Wizard option and then press the OK button. Click Next and you should see something like this:
Fill this out however you like and click Next (I called mine wxForm). This next screen allows you to choose where you want the application to be installed by default. It defaults to Program Files which is fine. Click Next. Now you should see the following screen:
Browse to the executable you created to add it. Then click the Add file(s)... button to add the rest. You can actually select all of the files except for the exe and hit OK. This is how mine turned out:
Now you’re ready to click Next. Make sure the Start Menu folder has the right name (in this case, wxForm) and continue. You can ignore the next two screens or experiment with them if you like. I’m not using a license or putting information files in to display to the user though. The last screen before finishing allows you to choose a directory to put the output into. I just left that empty since it defaults to where the executable is located, which is fine with this example. Click Next, Next and Finish. This will generate a full-fledged .iss file, which is what Inno Setup uses to turn your application into an installer. It will ask you if you’d like to go ahead and compile the script now. Go ahead and do that. Then it will ask if you’d like to save your .iss script. That’s a good idea, so go ahead and do that too. Hopefully you didn’t receive any errors and you can try out your new installer.
If you’re interested in learning about Inno’s scripting language, feel free to read Inno’s Documentation. You can do quite a bit with it. If you happen to make changes to your build script, you can rebuild your installer by going to the build menu and choosing the compile menu item.
Wrapping Up¶
At this point, you now know how to create a real, live installer that you can use to install your application and any files it needs to run. This is especially handy when you have a lot of custom icons for your toolbars or a default database, config file, etc that you need to distribute with your application. Go back and try creating the installer again, but choose different options to see what else you can do. Experimenting is a great way to learn. Just make sure you always have a backup in case something goes wrong!