2

I am preparing a setup file. What I want to do is auto select a component by comparing a registry key version and the user should not be able to modify these auto selected components.
Is there anyone who can help me on this issue, it would be greatly appreciated.

There will be five components and first two components should be auto-selected by the setup file comparing a registry version (I mean the setup file will decide which of the first two components will be choose and install.) and the other three components will be selected by the user, if the user want to install the additional files.

Or Is there any other way to install some files by comparing a registry key? So the setup file can automatically decide which files needs to be installed.

Let's say;

[Components]
Name: "FeatureA"; Description: "Feature A"
Name: "FeatureB"; Description: "Feature B"
Name: "FeatureC"; Description: "Feature C"

if RegKeyExists(HKEY_LOCAL_MACHINE,
     'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B8D22EE6-1S55-48BD-8B6F-B8961847F657}_is1') then
  begin<br />
     RegQueryStringValue(HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B8D22EE6-1S55-48BD-8B6F-B8961847F657}_is1', 'DisplayVersion', Version); then
if the version > 2.5.0.0 then
auto select "FeatureA"
else
if the version < 2.4.0.0 then
auto select "FeatureB"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Usr2284
  • 21
  • 2

1 Answers1

2

To install files under certain conditions only, use the Check parameter:

[Files]
Source: FeatureA.dll; DestDir: {app}; Check: ShouldInstallFeatureA
Source: FeatureB.dll; DestDir: {app}; Check: ShouldInstallFeatureB
[Code]

function GetVersion(var Version: string): Boolean;
begin
  Result :=
    RegQueryStringValue(
      HKEY_LOCAL_MACHINE,
      'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{B8D22EE6-1S55-48BD-8B6F-B8961847F657}_is1',
      'DisplayVersion', Version);
end;

function ShouldInstallFeatureA: Boolean;
var
  Version: string;
begin
  Result :=
    GetVersion(Version) and
    (CompareVersion(Version, '2.5.0.0') > 0);
end;

function ShouldInstallFeatureB: Boolean;
var
  Version: string;
begin
  Result :=
    GetVersion(Version) and
    (CompareVersion(Version, '2.4.0.0') < 0);
end;

For the CompareVersion function, see Compare version strings in Inno Setup.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I really appreciate for your help, I couldn't have done this without your help, Again, Thank you so much. – Usr2284 Jun 15 '22 at 11:43