我正在准备安装文件。我想要做的是通过比较注册表项版本来自动选择组件,并且用户不应该能够修改这些自动选择的组件。
有谁可以帮助我解决这个问题,我将不胜感激。
将有五个组件,前两个组件应由安装文件通过比较注册表版本自动选择(我的意思是安装文件将决定选择并安装前两个组件中的哪一个。)以及其他三个组件如果用户想要安装附加文件,组件将由用户选择。
或者是否有其他方法可以通过比较注册表项来安装某些文件?所以安装文件可以自动决定需要安装哪些文件。
比方说;
[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"
最佳答案
要仅在特定条件下安装文件,请使用 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;
有关 CompareVersion
函数,请参阅 Compare version strings in Inno Setup .
关于inno-setup - 根据注册表值决定在 Inno Setup 中安装哪些文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72625910/