Skip to content

Commit 01cb663

Browse files
committed
integrated uninstall before install
1 parent 475e61d commit 01cb663

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/setup/ExtraFunctions.iss

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
[Code]
22
3+
//from https://stackoverflow.com/questions/2000296/inno-setup-how-to-automatically-uninstall-previous-installed-version
4+
5+
/////////////////////////////////////////////////////////////////////
6+
function GetUninstallString(): String;
7+
var
8+
sUnInstPath: String;
9+
sUnInstallString: String;
10+
begin
11+
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
12+
sUnInstallString := '';
13+
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
14+
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
15+
Result := sUnInstallString;
16+
end;
17+
18+
19+
/////////////////////////////////////////////////////////////////////
20+
function IsUpgrade(): Boolean;
21+
begin
22+
Result := (GetUninstallString() <> '');
23+
end;
24+
25+
26+
/////////////////////////////////////////////////////////////////////
27+
function UnInstallOldVersion(): Integer;
28+
var
29+
sUnInstallString: String;
30+
iResultCode: Integer;
31+
begin
32+
// Return Values:
33+
// 1 - uninstall string is empty
34+
// 2 - error executing the UnInstallString
35+
// 3 - successfully executed the UnInstallString
36+
37+
// default return value
38+
Result := 0;
39+
40+
// get the uninstall string of the old app
41+
sUnInstallString := GetUninstallString();
42+
if sUnInstallString <> '' then begin
43+
sUnInstallString := RemoveQuotes(sUnInstallString);
44+
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
45+
Result := 3
46+
else
47+
Result := 2;
48+
end else
49+
Result := 1;
50+
end;
51+
52+
/////////////////////////////////////////////////////////////////////
53+
procedure CurStepChanged(CurStep: TSetupStep);
54+
begin
55+
if (CurStep=ssInstall) then
56+
begin
57+
if (IsUpgrade()) then
58+
begin
59+
UnInstallOldVersion();
60+
end;
61+
end;
62+
end;
63+
364
// Source of this function
465
// http://www.kynosarges.de/DotNetVersion.html
566
function IsDotNetDetected(version: string; service: cardinal): boolean;

0 commit comments

Comments
 (0)