0

I need to install some prerequisites for an app using Inno. I want the prerequisites to only install if the prerequisite does not exist or is an earlier version. I have found some solutions such as:

[Code]
procedure InstallFramework;
var
  ResultCode: Integer;
begin
  if not Exec(ExpandConstant('{tmp}\NDP472-KB4054530-x86-x64-AllOS-ENU.exe'), '/q /norestart', '', 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;
end;

That does not look like it checks to see if the framework exists already or what version may already be installed.

What is the pattern to use to look for a previously installed version, if it exists then check version and if version is older or does not exist then install?

Eric Snyder
  • 1,816
  • 3
  • 22
  • 46

1 Answers1

1

This a simple answer to head you in one of many possible solutions.

In the testing environment (or in your computer) you install the application and all the required components, so you have them appear in the control panel's Programs and Features

Programs and Features

Then you search in the registry for the name that appears in the Programs and Features

Registry

You want to find the value DisplayName that contains that name. You'll find it in one key of

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\, HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\

or

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

, depending of the type of installation.

Note: Some components can be hidden from the Programs and Features if the value SystemComponent is 1 in the correspondent key.

Then you can check the registry key existence with something like this in pascal script

[Code]
function test(bitness: integer; productCode: String): Boolean;
begin
    if RegValueExists(bitness, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + productCode, 'DisplayName') then Result := True else Result := False;
end;

You can call this function inside function PrepareToInstall(var NeedsRestart: Boolean): String; or using check parameters (search in inno setup help)

JPB
  • 31
  • 4