1
+ // The following code taken from https://stackoverflow.com/questions/2000296 /innosetup-how-to -automatically-uninstall-previous-installed-version
2
+ // It performs upgrades by running the uninstaller before the install
3
+
4
+ /////////////////////////////////////////////////////////////////////
5
+ function GetUninstallString(): String ;
6
+ var
7
+ sUnInstPath: String ;
8
+ sUnInstallString: String ;
9
+ begin
10
+ sUnInstPath := ExpandConstant(' Software\Microsoft\Windows\CurrentVersion\Uninstall\Rust_is1' );
11
+ sUnInstallString := ' ' ;
12
+ if not RegQueryStringValue(HKLM, sUnInstPath, ' UninstallString' , sUnInstallString) then
13
+ RegQueryStringValue(HKCU, sUnInstPath, ' UninstallString' , sUnInstallString);
14
+ Result := sUnInstallString;
15
+ end;
16
+
17
+
18
+ /////////////////////////////////////////////////////////////////////
19
+ function IsUpgrade(): Boolean;
20
+ begin
21
+ Result := (GetUninstallString() <> ' ' );
22
+ end;
23
+
24
+
25
+ /////////////////////////////////////////////////////////////////////
26
+ function UnInstallOldVersion(): Integer;
27
+ var
28
+ sUnInstallString: String ;
29
+ iResultCode: Integer;
30
+ begin
31
+ // Return Values:
32
+ // 1 - uninstall string is empty
33
+ // 2 - error executing the UnInstallString
34
+ // 3 - successfully executed the UnInstallString
35
+
36
+ // default return value
37
+ Result := 0 ;
38
+
39
+ // get the uninstall string of the old app
40
+ sUnInstallString := GetUninstallString();
41
+ if sUnInstallString <> ' ' then begin
42
+ sUnInstallString := RemoveQuotes(sUnInstallString);
43
+ if Exec(sUnInstallString, ' /SILENT /NORESTART /SUPPRESSMSGBOXES' ,' ' , SW_HIDE, ewWaitUntilTerminated, iResultCode) then
44
+ Result := 3
45
+ else
46
+ Result := 2 ;
47
+ end else
48
+ Result := 1 ;
49
+ end;
50
+
51
+ /////////////////////////////////////////////////////////////////////
52
+ procedure UpgradeCurStepChanged(CurStep: TSetupStep);
53
+ begin
54
+ if (CurStep= ssInstall) then
55
+ begin
56
+ if (IsUpgrade()) then
57
+ begin
58
+ UnInstallOldVersion();
59
+ end;
60
+ end;
61
+ end;
0 commit comments