I'm pretty sure that TLama or someone with experience will clean up the code, but you can use something like that for Check and Uninstall:
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;
Then you can embed your new installers of AppA and AppB into this one and run them by Extracting to temp and Executing.
Example:
[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..."
Or you can write the Executing script combining [Files]
and [Code]
sections:
embeding installers of App A and App B:
[Files]
Source: ".\AppA\setup_appa.exe"; DestDir: "{tmp}"; Flags: dontcopy
Source: ".\AppB\setup_appb.exe"; DestDir: "{tmp}"; Flags: dontcopy
and then calling to execute in [Code]
:
[Code]
Expanding function InitializeSetup: Boolean;
? Or placing elsewhere e.g. procedure CurPageChanged(CurPageID: Integer);
+ if CurPageID = wpInstalling then
//YOUR RUN SECTION HERE end;
with...
ExtractTemporaryFile('setup_appa.exe');
Exec(ExpandConstant('{tmp}'+'\setup_appa.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);