我很确定 TLama 或有经验的人会清理代码,但您可以使用类似的东西进行检查和卸载:
function GetUninstallStringA: string;
var
sUnInstPathA: string;
sUnInstallStringA: String;
begin
Result := '';
sUnInstPathA := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); //Your AppA GUID/ID
sUnInstallStringA := '';
if not RegQueryStringValue(HKLM, sUnInstPathA, 'UninstallString', sUnInstallStringA) then
RegQueryStringValue(HKCU, sUnInstPathA, 'UninstallString', sUnInstallStringA);
Result := sUnInstallStringA;
end;
function GetUninstallStringB: string;
var
sUnInstPathB: string;
sUnInstallStringB: String;
begin
Result := '';
sUnInstPathB := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C8}_is1'); //Your AppB GUID/ID
sUnInstallStringB := '';
if not RegQueryStringValue(HKLM, sUnInstPathB, 'UninstallString', sUnInstallStringB) then
RegQueryStringValue(HKCU, sUnInstPathB, 'UninstallString', sUnInstallStringB);
Result := sUnInstallStringB;
end;
function IsUpgradeA: Boolean;
begin
Result := (GetUninstallStringA <> '');
end;
function IsUpgradeB: Boolean;
begin
Result := (GetUninstallStringB <> '');
end;
function InitializeSetup: Boolean;
var
V: Integer;
iResultCodeA, iResultCodeB: Integer;
sUnInstallStringA, sUnInstallStringB: string;
AppA, AppB: Boolean;
begin
Result := True; // in case when no previous versions were found
AppA:= RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); //Your AppA GUID/ID
AppB:= RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A227028A-40D7-4695-8BA9-41DF6A3895C8}_is1'); //Your AppB GUID/ID
if (AppA) and (AppB) then begin
V := MsgBox(ExpandConstant('Hey! Old versions of Apps A and B were detected. Do you want to uninstall them?'), mbInformation, MB_YESNO);
//Custom Message if App installed
if V = IDYES then
begin
sUnInstallStringA := GetUninstallStringA;
sUnInstallStringA := RemoveQuotes(sUnInstallStringA);
Exec(ExpandConstant(sUnInstallStringA), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeA);
sUnInstallStringB := GetUninstallStringB;
sUnInstallStringB := RemoveQuotes(sUnInstallStringB);
Exec(ExpandConstant(sUnInstallStringB), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeB);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else begin
MsgBox('You have to uninstall older versions of Apps A and B first. Installation will now be terminated.', mbInformation, MB_OK);
Result := False; //when older versions present and not uninstalled
end;
end;
if (AppA) and (not AppB) then begin
V := MsgBox(ExpandConstant('Hey! Old version of App A was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO);
//Custom Message if App installed
if V = IDYES then
begin
sUnInstallStringA := GetUninstallStringA;
sUnInstallStringA := RemoveQuotes(sUnInstallStringA);
Exec(ExpandConstant(sUnInstallStringA), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeA);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else begin
MsgBox('You have to uninstall older version of App A first. Installation will now be terminated.', mbInformation, MB_OK);
Result := False; //when older versions present and not uninstalled
end;
end;
if (AppB) and (not AppA) then begin
V := MsgBox(ExpandConstant('Hey! Old version of App B was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO);
//Custom Message if App installed
if V = IDYES then
begin
sUnInstallStringB := GetUninstallStringB;
sUnInstallStringB := RemoveQuotes(sUnInstallStringB);
Exec(ExpandConstant(sUnInstallStringB), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeB);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else begin
MsgBox('You have to uninstall older version of App B first. Installation will now be terminated.', mbInformation, MB_OK);
Result := False; //when older versions present and not uninstalled
end;
end;
end;
然后,您可以将 AppA 和 AppB 的新安装程序嵌入到此安装程序中,并通过提取到临时和执行来运行它们。例子:
[Files]
Source: ".\AppA\setup_appa.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
Source: ".\AppB\setup_appb.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Run]
Filename: "{tmp}\setup_appa.exe"; Flags: waituntilterminated skipifdoesnotexist; StatusMsg: "Installing App A..."
Filename: "{tmp}\setup_appa.exe"; Flags: waituntilterminated skipifdoesnotexist; StatusMsg: "Installing App A..."
或者您可以编写 Executing 脚本结合[Files]
和[Code]
部分:
嵌入 App A 和 App B 的安装程序:
[Files]
Source: ".\AppA\setup_appa.exe"; DestDir: "{tmp}"; Flags: dontcopy
Source: ".\AppB\setup_appb.exe"; DestDir: "{tmp}"; Flags: dontcopy
然后调用执行[Code]
:
[Code]
扩大function InitializeSetup: Boolean;
?或放置在其他地方,例如procedure CurPageChanged(CurPageID: Integer);
+与...if CurPageID = wpInstalling then
//YOUR RUN SECTION HERE end;
ExtractTemporaryFile('setup_appa.exe');
Exec(ExpandConstant('{tmp}'+'\setup_appa.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);