Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup launch executable (to install drivers) during installation

Tags:

inno-setup

I am using Inno Setup to create an installer for my application. The installer is very basic and just copies some files. This works very well and I am happy with it.

I recently implemented USB support and need to install the USB driver from the IVI foundation for that. It is basically an exe file that has to be launched somewhere during the setup process. Until now, the user has to install the drivers separately, which is not so elegant. My first approach was this:

[Run]
Filename: "{app}\driver\IviSharedComponents_2.2.1.exe"; Description: "Install USB driver (IVI Foundation)"; Flags: postinstall skipifsilent
Filename: "{app}\driver\IviSharedComponents64_2.2.1.exe"; Description: "Install 64bit USB driver (IVI Foundation)"; Flags: postinstall skipifsilent
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: postinstall skipifsilent

This works, but the user has to select the correct bitness. The advantage here is that he can choose not to install it (in which case the application just ignores the USB functionality which is fine). What I actually want is to detect the bitness of the system automatically and run the setup process. This does not have to be in the [Run] section, although I would not have anything against it (because the user can choose not to install it).

I also found some code and tried to run it like this:

[Code]
procedure CurStepChanged (CurStep: TSetupStep);
var
   WorkingDir:   String;
   ReturnCode:   Integer;
begin    
   if (ssInstall = CurStep) then
     Log('Starting driver installation');
     WorkingDir := ExpandConstant ('{app}\driver');
     Exec ('IviSharedComponents_2.2.1.exe', '', WorkingDir, SW_SHOW, ewWaitUntilTerminated, ReturnCode);
end;

But this does not start the installation (although I can see the log entry 'Starting driver installation'). Is there something wrong with my path? What am I doing wrong and how could I change this script to automatically select the right executable depending on the bitness?

EDIT: I used the proposed solution with the [Tasks] entry. The implementation looks like this (just for reference):

[Tasks]
Name: "install_usb"; Description: "Install USB drivers (IVI Foundation)"; GroupDescription: "External drivers:";

[Run]
Filename: "{app}\driver\IviSharedComponents_2.2.1.exe"; StatusMsg: "Installing USB driver (IVI Foundation)"; Check: Not IsWin64(); Tasks: install_usb; Flags: skipifsilent
Filename: "{app}\driver\IviSharedComponents64_2.2.1.exe"; StatusMsg: "Installing USB driver (IVI Foundation)"; Check: IsWin64(); Tasks: install_usb; Flags: skipifsilent

This works very well, thanks a lot for your help!

like image 393
brimborium Avatar asked Jul 10 '12 15:07

brimborium


1 Answers

In this case, it's best to remove the postinstall flag so it runs unconditionally at the end of the setup process (but before it says finished) and add a Check: parameter to limit it to the correct bitness:

[Run]
Filename: "{app}\driver\IviSharedComponents_2.2.1.exe"; StatusMsg: "Installing USB driver (IVI Foundation)"; Check: Not IsWin64(); Flags: skipifsilent
Filename: "{app}\driver\IviSharedComponents64_2.2.1.exe"; StatusMsg: "Installing USB driver (IVI Foundation)"; Check: IsWin64(); Flags: skipifsilent

If you want this to be conditional, you can use a normal [Tasks] entry that prompts before the setup starts.

like image 196
Deanna Avatar answered Oct 15 '22 16:10

Deanna