2

My InnoSetup Script needs to install the VC redistributables (vcredist_x86.exe) but also registers an OCX relying on the redist package. I wasn't able to have the package installed prior to the regsrv32 call, so on a virgin system it always results in a "RegSrv32 failed with exit code 0x1" error (which I could ignore and run the setup again to correctly register the OCX). How can I make sure the redist package is installed before registering?

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
AppName=MyApp
AppVerName=MyApp v1.0
DiskSpanning=no
AppPublisher=me
AppPublisherURL=http://www.example.com
AppSupportURL=http://www.example.com
AppUpdatesURL=http://www.example.com
DefaultDirName={pf}\MyApp
UsePreviousAppDir=yes
DefaultGroupName=MyApp
OutputBaseFilename=Setup
OutputDir=.\MyAppSetup
MinVersion=5.0

[Tasks]
Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:; MinVersion: 4,4

[Files]
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\msvcm90.dll"; DestDir: {app};
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\msvcp90.dll"; DestDir: {app};
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\msvcr90.dll"; DestDir: {app};
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.ATL\atl90.dll"; DestDir: {app};
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.MFC\mfc90.dll"; DestDir: {app};
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.MFCLOC\MFC90DEU.dll"; DestDir: {app};
;Source: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.OPENMP\vcomp90.dll"; DestDir: {app};      
Source: .\SystemFiles\vcredist_x86.exe; DestDir: {tmp}; Flags: deleteafterinstall;   
;-> [Run] !!

Source: .\Release\MyApp.exe; DestDir: {app}; Flags: ignoreversion
Source: .\Release\MyAppHelper.ocx; DestDir: {app}; Flags: regserver restartreplace  

[Icons]
Name: {group}\EasyCash&Tax; Filename: {app}\MyApp.exe
Name: {userdesktop}\EasyCash&Tax; Filename: {app}\MyApp.exe; MinVersion: 4,4; Tasks: desktopicon

[Run]
Filename: {tmp}\vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; Flags: runhidden shellexec waituntilterminated;
Filename: {app}\MyApp.exe; Description: Launch MyApp; Flags: nowait postinstall skipifsilent
thomiel
  • 2,467
  • 22
  • 37
  • The `[Run]` section is processed after `[Files]`. Move your redist installation to the `PrepareToInstall` event function. – TLama Jun 03 '15 at 10:22
  • 1
    But I need to temporarily install the file to {tmp}\vcredist_x86.exe first in order to run it. Can you provide working code in an answer? That would be awesome. – thomiel Jun 03 '15 at 10:37
  • I think this might get you started http://pastebin.com/33ZebFsF. – TLama Jun 03 '15 at 11:04
  • 1
    Perfect! Exactly what I was looking for. Don't be too shy to use the answer option instead of a comment! ;) – thomiel Jun 03 '15 at 13:23

1 Answers1

2

For your convinience, here is the code from pastebin TLama referred me to:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Files]
Source: ".\SystemFiles\vcredist_x86.exe"; Flags: dontcopy

[Code]
function IsRuntimeInstalled: Boolean;
begin
  Result := False;
  // here will be a statement that will check whether the runtime is installed
  // and return True if so; see e.g. http://stackoverflow.com/q/11137424/960757
end;

function PrepareToInstall(var NeedsRestart: Boolean): string;
var
  ExitCode: Integer;
begin
  // if the runtime is not already installed
  if not IsRuntimeInstalled then
  begin
    // extract the redist to the temporary folder
    ExtractTemporaryFile('vcredist_x86.exe');
    // run the redist from the temp folder; if that fails, return from this handler the error text
    if not Exec(ExpandConstant('{tmp}\vcredist_x86.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ExitCode) then
    begin
      // return the error text
      Result := 'Setup failed to install VC++ runtime. Exit code: ' + IntToStr(ExitCode);
      // exit this function; this makes sense only if there are further prerequisites to install; in this
      // particular example it does nothing because the function exits anyway, so it is pointless here
      Exit;
    end;
  end;
end;
thomiel
  • 2,467
  • 22
  • 37