Skip to content

Commit 821853a

Browse files
committed
setup: uninstall msi when executing uninstall via inno setup
1 parent bf91582 commit 821853a

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎BrowserGuard.iss‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const
9292
// hand or by a group policy is not removed on uninstall.
9393
OwnKey = 'Software\BrowserGuard';
9494
RegisteredFlag = 'ExtensionSettingsRegistered';
95+
MsiProductCode = '{E039FF7F-1CD4-42D7-A254-0ADD92E6517D}';
9596
9697
function GetProgramFiles(Param: string): string;
9798
begin
@@ -215,6 +216,29 @@ begin
215216
end;
216217
end;
217218
219+
function MsiPackageInstalled(): Boolean;
220+
begin
221+
Result := RegKeyExists(HKEY_LOCAL_MACHINE,
222+
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + MsiProductCode);
223+
end;
224+
225+
procedure UninstallMsiPackage();
226+
var
227+
ResultCode: Integer;
228+
begin
229+
if ExpandConstant('{param:UninstallMsiPackage|yes}') <> 'yes' then
230+
Exit;
231+
if not MsiPackageInstalled() then
232+
Exit;
233+
234+
if not Exec('msiexec.exe',
235+
'/x ' + MsiProductCode + ' /qn UNINSTALL_EXE_PACKAGE=no',
236+
'', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
237+
Log('Cannot start msiexec.exe')
238+
else if ResultCode <> 0 then
239+
Log('msiexec returned ' + IntToStr(ResultCode) + ' for ' + MsiProductCode);
240+
end;
241+
218242
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
219243
var
220244
Flag: String;
@@ -227,4 +251,5 @@ begin
227251
if Flag = '1' then
228252
UnregisterExtensionSettings();
229253
end;
254+
UninstallMsiPackage();
230255
end;

‎BrowserGuardMsiSetup/Package.wxs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2-
<!-- ProductCode is left out on purpose, so that WiX generates a new one for
3-
every build. A pinned ProductCode would make MajorUpgrade unreachable:
4-
MSI would read the next version as the same product. -->
2+
<!-- ProductCode is pinned because BrowserGuard.iss has to name it: removing
3+
the Inno Setup package on its own would otherwise leave this one behind.
4+
It must still differ from one version to the next, or MajorUpgrade never
5+
fires and MSI reads the new version as the same product. bump-version.ps1
6+
generates a new one and writes it to both files. -->
57
<Package Name="BrowserGuard" Manufacturer="ClearCode Inc." Version="$(var.Version)"
6-
UpgradeCode="390BAE83-8789-4D2C-BDCF-085335FA8E79">
8+
UpgradeCode="390BAE83-8789-4D2C-BDCF-085335FA8E79"
9+
ProductCode="E039FF7F-1CD4-42D7-A254-0ADD92E6517D">
710
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
811
<Media Id="1" EmbedCab="yes" Cabinet="cab1.cab" />
912
<Feature Id="Main">

‎BrowserGuardMsiSetup/tools/uninstall-exe-package.cmd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ reg query "%~1" /v UninstallString %2 >nul 2>&1
1818
if not %errorlevel% equ 0 exit /b 0
1919
for /f "tokens=2*" %%A in ('reg query "%~1" /v UninstallString %2') do set "UNINSTALL_PATH=%%B"
2020
if not defined UNINSTALL_PATH exit /b 0
21-
call !UNINSTALL_PATH! /VERYSILENT /SUPPRESSMSGBOXES /NORESTART
21+
call !UNINSTALL_PATH! /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /UninstallMsiPackage=no
2222
set "UNINSTALL_PATH="
2323
exit /b 0

0 commit comments

Comments
 (0)