根据注册表值决定在Inno Setup中安装哪些文件



我正在准备一个安装文件。我想做的是通过比较注册表项版本来自动选择组件,用户不应该能够修改这些自动选择的组件。
有谁能在这个问题上帮助我,我将不胜感激。

将有五个组件,前两个组件应该由安装文件比较注册表版本自动选择(我的意思是安装文件将决定选择和安装前两个组件中的哪一个),其他三个组件将由用户选择,如果用户想要安装其他文件。

或者是否有其他方法通过比较注册表项来安装一些文件?因此,安装文件可以自动决定需要安装哪些文件。

假设;

[Components]
Name: "FeatureA"; Description: "Feature A"
Name: "FeatureB"; Description: "Feature B"
Name: "FeatureC"; Description: "Feature C"
if RegKeyExists(HKEY_LOCAL_MACHINE,
'SOFTWAREMicrosoftWindowsCurrentVersionUninstall{B8D22EE6-1S55-48BD-8B6F-B8961847F657}_is1') then
begin<br />
RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SOFTWAREMicrosoftWindowsCurrentVersionUninstall{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"

仅在某些条件下安装文件,使用Check参数:

[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,
'SOFTWAREMicrosoftWindowsCurrentVersionUninstall{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;

CompareVersion功能请参见Inno Setup中的比较版本字符串。