Inno Setup How to exclude a single file from AfterInstall - inno-setup

After install, I want to save a string to 3 out of the 4 files, but currently it's saving the string to all. How do I exclude a file called network? I'm thinking another if statement, but not sure how. This file would be {app}\configs\network.config
procedure MyBeforeInstall;
begin
if(FileExists(ExpandConstant(CurrentFileName))) then
begin
Exists := True;
end
else
begin
Exists := False;
end;
end;
procedure MyAfterInstall;
begin
if not(Exists) then
SaveStringToFile(ExpandConstant(CurrentFileName), #13#10 + 'SettingEnv ' + SettingEnv.Values[0] + #13#10, True);
MsgBox(ExpandConstant(CurrentFileName), mbInformation, MB_OK);
end;

Assuming you use MyBeforeInstall and MyAfterInstall like this:
[Files]
Source: "*.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Then you can do this instead:
[Files]
Source: "one.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "two.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "three.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "but_not_this_one.txt"; DestDir: "{app}"
This will do too:
[Files]
Source: "*.txt"; Excludes: "but_no_this_one.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "but_not_this_one.txt"; DestDir: "{app}"
Yet another option is:
procedure MyAfterInstall;
begin
if CompareText(ExtractFileName(CurrentFileName), 'but_not_this_one.txt') <> 0 then
begin
if not Exists then
SaveStringToFile(
CurrentFileName,
#13#10 + 'SettingEnv ' + SettingEnv.Values[0] + #13#10, True);
end;
MsgBox(CurrentFileName, mbInformation, MB_OK);
end;
(ntb, that there's no point using ExpandConstant on CurrentFileName, as its return value does not contain any constants)

Related

Find path to a program (sqlcmd) installed by child subinstaller of Inno Setup

In my scenario I need to run .sql script at the end of my setup with sqlcmd.exe. But each version of SQL Server uses different paths for sqlcmd.
I'm trying some solutions to use sqlcmd but none work.
As a last test I created an installer just to run my script but even this doesn't recognize sqlcmd as a command.
Is there a way to retrieve the sqlcmd path with a function in order to pass the value to [Run] section?
Any suggestions are welcome.
Thanks
This is my code I'm trying
Main installer.exe
[Setup]
PrivilegesRequired=admin
[Files]
; sql server 2019 Express
Source: "..\PREREQUIREMENTS\SQL\SQLSERVER\2019\SQLEXPR_x64_ENU.exe"; \
DestDir: "{tmp}"; DestName: "SQLSERVER2019.exe"; Flags: ignoreversion; \
MinVersion: 10.0.17134; Tasks: SQL
; sql server 2014 Express
Source: "..\PREREQUIREMENTS\SQL\SQLSERVER\2014\SQLEXPR_x64_ENU.exe"; \
DestDir: "{tmp}"; DestName: "SQLSERVER2014SP3.exe"; Flags: ignoreversion; \
OnlyBelowVersion: 10.0.17134; Tasks: SQL
; sql management studio 18
Source: "..\PREREQUIREMENTS\SQL\SSMS\SSMS-Setup-ENU.exe"; DestDir: "{tmp}"; \
DestName: "SSMS18.exe"; Flags: ignoreversion; Tasks: SSMS
; SQLCMD
Source: "src\DB\ADM_DB_installer.exe"; DestDir: "{tmp}"; Flags: ignoreversion; \
Components: ADM
ADM_DB_installer.exe
[Setup]
PrivilegesRequired=admin
[Run]
Filename: "sqlcmd.exe"; \
Parameters: "-v ADMPRIMARY=""{code:GetSQLVar|DBPATH}"" ADMDATA=""{code:GetSQLVar|DBPATH}"" ADMINDEX=""{code:GetSQLVar|DBPATH}"" ADMLOG=""{code:GetSQLVar|DBPATH}"" -S {code:GetSQLVar|SQLSERVER}\{code:GetSQLVar|INSTANCE} -U sa -P {code:GetSQLVar|SAPWD} -i ""{tmp}\CREATE_ADM_DB_1.0.0.sql"" -o ""{code:GetSQLVar|DBPATH}\log.txt"""
There might be a better solution, but what you can do is to read the PATH from registry and use FileSearch to find the program.
[Run]
Filename: "{code:FileSearchInPath|sqlcmd.exe}"; Parameters: "..."
[Code]
const
EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
function FileSearchInPath(FileName: string): string;
var
Path: string;
begin
Result := '';
if not RegQueryStringValue(HKLM, EnvironmentKey, 'PATH', Path) then
begin
Log('Cannot read PATH');
end
else
begin
Log(Format('PATH is %s', [Path]));
Result := FileSearch(FileName, Path);
if Result = '' then
begin
Log(Format('Cannot find %s', [FileName]));
end
else
begin
Log(Format('Found %s', [Result]));
end;
end;
if Result = '' then Result := FileName; // let it fail later
end;
The above code searches only system PATH, not user PATH.
You do not need a separate installer to execute the sqlcmd.exe.

How to complete instalation ant then restart windows?

I try to rework existing inno setup script and include some dependencies to it. But at the middle of installation VC++ redistributable always restart the windows not from installing wizard window. And this restart totally has broken all installation progress. I have this script.
[Files]
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Launcher\AAC Psychologue.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Launcher\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\dxwebsetup.exe"; DestDir: "{app}"; AfterInstall: DirecXinstaller; Flags: ignoreversion deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\Windows6.1-KB2670838-x64.msu"; DestDir: "{app}"; Flags: 64bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\Windows6.1-KB2670838-x86.msu"; DestDir: "{app}"; AfterInstall: Win7Update; Flags: 32bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\Windows6.1-KB2670838-x86.msu"; DestDir: "{app}"; AfterInstall: Win7Update; Flags: 32bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\vc_redist.x86.exe"; DestDir: "{app}";AfterInstall: vcInstaller; Flags: 32bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\vc_redist.x64.exe"; DestDir: "{app}";AfterInstall: vcInstaller; Flags: 64bit deleteafterinstall
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}";
[Code]
procedure DirecXinstaller;
var
ResultCode: Integer;
begin
if not Exec(ExpandConstant('{app}\dxwebsetup.exe'), '', '', SW_SHOWNORMAL,
ewWaitUntilTerminated, ResultCode)
then
MsgBox('Other installer failed to run!' + #13#10 +
SysErrorMessage(ResultCode), mbError, MB_OK);
end;
procedure Win7Update;
var
ResultCode: Integer;
begin
if IsWin64 then
begin
Exec(ExpandConstant('{app}\Windows6.1-KB2670838-x64.msu'), '', '', SW_SHOWNORMAL,
ewWaitUntilTerminated, ResultCode)
end
else
begin
Exec(ExpandConstant('{app}\Windows6.1-KB2670838-x86.msu'), '', '', SW_SHOWNORMAL,
ewWaitUntilTerminated, ResultCode)
end;
end;
procedure vcInstaller;
var
ResultCode: Integer;
begin
if IsWin64 then
begin
Exec(ExpandConstant('{app}\vc_redist.x64.exe'), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode)
end
else
begin
Exec(ExpandConstant('{app}\vc_redist.x86.exe'), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode)
end;
end;
[Run]
Filename: "{app}\{#MyAppExeName}"; Flags: postinstall skipifsilent waituntilterminated unchecked;
Have any ideas?
vc_redist.*.exe have /norestart switch to prevent the restart.
You can then make Inno Setup restart the machine using AlwaysRestart directive.
Also, note that it is better to use [Run] section to execute the sub-installer. Additionally, it not a good practice to install temporary files to {app}. I also do not think that you want to use ewNoWait.
[Setup]
AlwaysRestart=yes
[Files]
Source: "...\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: 32bit
Source: "...\vc_redist.x64.exe"; DestDir: "{tmp}"; Flags: 64bit
[Run]
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/norestart"; Flags: 32bit
Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/norestart"; Flags: 64bit

Inno setup script doesn't run accessruntime after installing .net

I have some troubles with the installer script
I want to install my app and it needs .net 4.5 to be installed on the host. Also it needs AccessRuntime2007.
I have some troubles because the Accessruntime will not install using the script.
Maybe something wrong with the sequence? who can help me?
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "JazzNotes"
#define MyAppVersion "1.0"
#define MyAppPublisher "EMDEE TECH"
#define MyAppURL "www.jazznotes.com"
#define MyAppExeName "JazzNotes.exe"
[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={{2F4E8FD6-6151-45A1-A421-8CA123E312CF}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\license.txt
OutputDir=C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\inno output
OutputBaseFilename=Install Jazznotes
SetupIconFile=C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\icons\Itzikgur-My-Seven-Music-Piano-Chello.ico
Compression=lzma
SolidCompression=yes
[Types]
Name: "full"; Description: "Full installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom
[Components]
Name: "program"; Description: "Program Files"; Types: full custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "Net"; Description: ".NET 4.5 Framework"; Types: full
Name: "Acrobat" ; Description: "Acrobat Reader 8"; Types: full
Name: "Access" ; Description: "Access runtime files"; Types: full
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "dependencies\AccessRuntime.exe"; DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallFramework2; Components: Access
Source: "dependencies\AdbeRdr11010_en_US.exe"; DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallFramework3; Components: Acrobat
Source: "dependencies\dotnetfx45_full_x86_x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallFramework; Check: FrameworkIsNotInstalled ;Components: Net
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\JazzNotes.exe"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\AxInterop.AcroPDFLib.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\AxInterop.WMPLib.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\Interop.AcroPDFLib.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\Interop.WMPLib.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\JazzNotes.exe.config"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\NAudio.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\bin\x86\Release\UltraID3Lib.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualBasic.Compatibility.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Deployment.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Design.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Drawing.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.XML.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\stdole.dll"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\LTYPE.TTF"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\LTYPEB.TTF"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\LTYPEBO.TTF"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\MusiCAT\LTYPEO.TTF"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\jingle.wav"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
Source: "C:\Users\donnersm\Documents\Visual Studio 2015\Projects\MusiCAT\musica.accdb"; DestDir: "{app}"; Flags: ignoreversion ; Components: program
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Code]
function FrameworkIsNotInstalled: Boolean;
begin
Result := not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\.NETFramework\policy\v4.5');
end;
procedure InstallFramework;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing .NET framework...';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
if not Exec(ExpandConstant('{tmp}\dotnetfx45_full_x86_x64.exe'), '/q /noreboot', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// you can interact with the user that the installation failed
MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.',
mbError, MB_OK);
end;
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
end;
end;
procedure InstallFramework2;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing Access Runtime files...';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
if not Exec(ExpandConstant('{tmp}\AccessRuntime.exe'), '/q /noreboot', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// you can interact with the user that the installation failed
MsgBox('Access Runtime installation failed with code: ' + IntToStr(ResultCode) + '.',
mbError, MB_OK);
end;
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
end;
end;
procedure InstallFramework3;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing Acrobar Reader';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
if not Exec(ExpandConstant('{tmp}\AdbeRdr11010_en_US.exe'), '/q /noreboot', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// you can interact with the user that the installation failed
MsgBox('Acrobat installation failed with code: ' + IntToStr(ResultCode) + '.',
mbError, MB_OK);
end;
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
end;
end;
[Icons]
Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
Thanks Martin ! Your advise in removing the /q helped! Turns out that the accessruntime.exe does not allow the /noreboot....i changed it to /norestart... and it worked!

How to selectively create a directory, copy files and run a batch file in InnoSetup [duplicate]

Alternatively is it possible to manually update the built in progress bar?
Basically I have 2 MSIs included and using Inno Setup as a bootstrapper, and depending on user input one or both of the MSIs are to be installed. I have something working using Exec statements in CurStepChanged but it doesn't update the progress bar as the files are extracted and it looks like the installer is stalled. I guess the end result is I want some progress bar updates while the files are extracted to the temp folder. The following is my current code:
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
begin
if(CurStep = ssInstall) then begin
if(InstallServer) then begin
ExtractTemporaryFile('ServerSetup.msi');
Exec('msiexec',ExpandConstant('/i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2'),'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
if(InstallClient) then begin
ExtractTemporaryFile('ClientSetup.msi');
Exec('msiexec',ExpandConstant('/i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2'),'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
end;
end;
Why not simply try something like this:
[Files]
Source: ClientSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Components: Client
Source: ServerSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Components: Server
[Run]
Filename: msiexec.exe; Parameters: /i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing client; Components: Client
Filename: msiexec.exe; Parameters: /i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing server; Components: Server
[Components]
Name: Client; Description: Client Installation
Name: Server; Description: Server Installation
Of course you don't necessarily have to use Components. You did not write how you decide which installer to run. If you need more complex logic you could also use Check functions as in:
[Files]
Source: ClientSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Check: CheckClient
Source: ServerSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Check: CheckServer
[Run]
Filename: msiexec.exe; Parameters: /i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing client; Check: CheckClient
Filename: msiexec.exe; Parameters: /i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing server; Check: CheckServer
[Code]
function CheckClient: Boolean;
begin
Result := WhateverCondition;
end;
function CheckServer: Boolean;
begin
Result := WhateverOtherCondition;
end;

Problem with checking the Windows version from Inno Setup

My program installs a driver, which has different versions compiled for XP, Win2003, Vista/Win2008, and Win7. I use pascal functions to check which is the OS, and install the corresponding DLL.
On some users' systems no DLL is installed, which means all the functions have returned false. This should not happen so long as the OS's major version is 5 or 6.
Can anyone tell me if there is something wrong with the code I use?
[Code]
function UseDriverForWindows7(): Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
// Windows 7 version is 6.1 (workstation)
if (Version.Major = 6) and
(Version.Minor = 1) and
(Version.ProductType = VER_NT_WORKSTATION)
then
Result := True
else
Result := False;
end;
function UseDriverForWindowsVistaAndWindows2008(): Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
// Anything with major version 6 where we won't use Windows 7 driver
if (Version.Major = 6) and
(not UseDriverForWindows7)
then
Result := True
else
Result := False;
end;
function UseDriverForWindows2003(): Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
// Windows 2003 version is 5.2 (server)
if (Version.Major = 5) and
(Version.Minor = 2) and
(Version.ProductType <> VER_NT_WORKSTATION)
then
Result := True
else
Result := False;
end;
function UseDriverForWindowsXP(): Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
// Anything with major version 5 where we won't use Windows 2003 driver
if (Version.Major = 5) and
(not UseDriverForWindows2003)
then
Result := True
else
Result := False;
end;
[Files]
Source: "mydrv-xp-x86.dll"; DestDir: {app}; DestName: mydrv.dll; Check: not IsWin64 and UseDriverForWindowsXP; Flags: ignoreversion
Source: "mydrv-2003-x86.dll"; DestDir: {app}; DestName: mydrv.dll; Check: not IsWin64 and UseDriverForWindows2003; Flags: ignoreversion
Source: "mydrv-vista-x86.dll"; DestDir: {app}; DestName: mydrv.dll; Check: not IsWin64 and UseDriverForWindowsVistaAndWindows2008; Flags: ignoreversion
Source: "mydrv-win7-x86.dll"; DestDir: {app}; DestName: mydrv.dll; Check: not IsWin64 and UseDriverForWindows7; Flags: ignoreversion
Source: "mydrv-xp-x64.dll"; DestDir: {app}; DestName: mydrv.dll; Check: IsWin64 and UseDriverForWindows2003; Flags: ignoreversion
Source: "mydrv-vista-x64.dll"; DestDir: {app}; DestName: mydrv.dll; Check: IsWin64 and UseDriverForWindowsVistaAndWindows2008; Flags: ignoreversion
Source: "mydrv-win7-x64.dll"; DestDir: {app}; DestName: mydrv.dll; Check: IsWin64 and UseDriverForWindows7; Flags: ignoreversion
You should use the common parameters MinVersion and OnlyBelowVersion in conjunction with the function IsWin64.
Update
To distinguish between workstation and server versions you can use the GetWindowsVersionEx function which is integrated in Inno Setup.

Resources