The main features a generated installer has are:
- it creates a single exe file you can use to install your application on other computers
- you can add customizable setup types
- you can specify uninstall options
- you can choose what shortcuts to be created when installing the program
- you can create registry entries
- you can run other programs before, during or after the install
- you can add advanced install and uninstall options using the integrated pascal scripting engine
I will not go into the details of creating a simple installer. Inno setup also has a Script Wizard that can be used to generate the script for the installer.
Here’s an example of a generated script:
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{E80CC92C-D4F2-4E90-988E-0134482AFB87}
AppName=My Program
AppVerName=My Program 1.5
AppPublisher=My Company, Inc.
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "C:\Program Files\Inno Setup 5\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
Name: "{commondesktop}\My Program"; Filename: "{app}\MyProg.exe"; Tasks: desktopicon
[Run]
Filename: "{app}\MyProg.exe"; Description: "{cm:LaunchProgram,My Program}"; Flags: nowait postinstall skipifsilent
This can be used to install a program on your computer, in the folder specified by the user.
Some of the programs you make might require some other applications to be installed to be able to run. What I am going to show in this tutorial is how to use inno setup to write an installer script that checks if a program is installed on the computer and, if not, it installs the necessary program before resuming the installer.
The script I wrote checks if the 3.5 version of .NET framework is installed.
For this, I added a code section in the script and wrote a function to do the checking.
The function looks like this:
[CustomMessages]
dotnetmissing=This application needs Microsoft .Net Version 3.5. Do you like to install it now?
[Code]
function InitializeSetup(): Boolean;
var
ErrorCode: Integer;
ResultCode: Integer;
netFrameWorkInstalled : Boolean;
isInstalled: Cardinal;
begin
result := true;
// Check for the .Net 3.5 framework
isInstalled := 0;
netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', isInstalled);
if ((netFrameworkInstalled) and (isInstalled <> 1)) then netFrameworkInstalled := false;
if netFrameworkInstalled = false then
begin
if (MsgBox(ExpandConstant('{cm:dotnetmissing}'),
mbConfirmation, MB_YESNO) = idYes) then
begin
if Exec(ExpandConstant('dotNetFx35setup.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// check if .net was installed properly
isInstalled := 0;
netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', isInstalled);
if ((netFrameworkInstalled) and (isInstalled <> 1)) then netFrameworkInstalled := false;
if netFrameworkInstalled = false then
// not installed
begin
MsgBox('.NET 3.5 was not installed properly. Please restart the installer.', mbConfirmation, MB_OK);
result := false;
end
// installed
else begin
MsgBox('.NET 3.5 was installed properly.', mbConfirmation, MB_OK);
result := true;
end;
end
else begin
MsgBox('An error occurer while installing .NET 3.5. Please restart the installer.', mbConfirmation, MB_OK);
result := false;
end;
end
else begin
result := false;
end;
end;
end;
The InitializeSetup function is called before running the setup. If it returns true, the setup continues, if not, the setup ends.
First, we check if .NET 3.5 is installed. For this, we check the appropriate registry key:
netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', isInstalled);
The RegQueryDWordValue function has the following prototype:
function RegQueryDWordValue(const RootKey: Integer; const SubKeyName, ValueName: String; var ResultDWord: Cardinal): Boolean;
It queries the specified registry value and returns the data in ResultDWord.
If .NET is installed, the InitializeSetup function returns true, and the setup continues.
If .NET is not installed, a message box is shown to the user to let them know they need to install .NET 3.5 (a custom message is printed in the message box and the user can choose whether to install .NET or not):
MsgBox(ExpandConstant('{cm:dotnetmissing}'), mbConfirmation, MB_YESNO)
If the user chooses to install the .NET framework, we will run the installer for .NET:
Exec(ExpandConstant('dotNetFx35setup.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
The Exec function is used to execute another program.
After the function finishes execution, we check if .NET was installed properly (we check the registry key again). If the key was set, it means there were no problems while installing .NET and we resume our installation. If there were problems while installing .NET, we show the appropriate message to the user and cancel the setup.





MultiQuote




|