随着使用RegQueryStringValue功能 and CompareVersion
函数来自比较 Inno Setup 中的版本字符串(你的问题),你可以这样做:
#define MyAppVersion "2.6"
[Code]
function InitializeSetup(): Boolean;
var
InstalledVersion: string;
VersionDiff: Integer;
begin
Result := True;
if not RegQueryStringValue(
HKCU, 'Software\My Program', 'DSVersionL4D2', InstalledVersion) then
begin
Log('No installed version detected');
end
else
begin
Log(Format('Found installed version %s', [InstalledVersion]));
VersionDiff := CompareVersion(InstalledVersion, '{#MyAppVersion}');
if VersionDiff < 0 then
begin
MsgBox(
Format('You have an old version %s installed, will uninstall it.', [
InstalledVersion]),
mbInformation, MB_OK);
{ Uninstall old version here }
end
else
if VersionDiff = 0 then
begin
MsgBox(
'You have this version installed already, cancelling installation.',
mbInformation, MB_OK);
Result := False;
end
else
begin
MsgBox(
Format(
'You have newer version %s installed already, ' +
'cancelling installation.', [InstalledVersion]),
mbInformation, MB_OK);
Result := False;
end;
end;
end;
只需插入问题中链接的一些答案中的卸载代码即可。
但请注意,您不需要编写自己的版本注册表值。有DisplayVersion
, VersionMajor
and VersionMinor
在标准卸载注册表项中。