|
1 | 1 | [Code] |
2 | 2 |
|
| 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 | +
|
3 | 64 | // Source of this function |
4 | 65 | // http://www.kynosarges.de/DotNetVersion.html |
5 | 66 | function IsDotNetDetected(version: string; service: cardinal): boolean; |
|
0 commit comments