1

In Inno setup, I want to check whether previous version of an application is installed, and uninstall it automatically if it is detected. The registry key to check if the application exists is this: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Shockwave Player And the silent uninstallation command is this: C:\Windows\system32\Adobe\Shockwave 12\uninstaller.exe /S . Note-The setup of the application was developed using NSIS.

And one more thing, I want no message box to be shown if previous version is found. The previous version of the same application is v12.1.3.153 or lower. Full Inno script for any reference: http://pastebin.com/HmrNcFd4

So please provide the code. Thanks a lot!!

the_Ma5TeR
  • 302
  • 3
  • 11
  • You should [`compare version`](http://stackoverflow.com/a/22356942/960757) value from `DisplayVersion` from that reg. key (note that there can be 64-bit player installed, so you should check that in both views) against what you're going to install. If that version is lower, run what is stored in the `UninstallString` key value (or execute [`uninstaller from here`](http://www.adobe.com/shockwave/download/alternates/#sp)). – TLama Nov 24 '14 at 15:07

1 Answers1

1

First you create a new GUID for your application (it's like a primary key for your application in the registry)

; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
#define MyAppGUID "D8C85F98-A805-4237-8D7C-C2F050C19B47"
#define MyAppId MyAppName + "_" + MyAppGUID

Add this instruction in section [Code] and in function InitializeSetup().

[Code]
function InitializeSetup(): Boolean;
var
  ResultCode: Integer;
  ResultStr:string;
begin
  // Check if the application is already install
  // MsgBox('MyAppId = ' + '{#MyAppId}', mbInformation, mb_Ok);
  begin
    If RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'UninstallString', ResultStr) then begin
      If ResultStr<>'' then begin
        ResultStr:=RemoveQuotes(ResultStr);
          if MsgBox('This application is already install. ' #13#13 'Uninstall it ?', mbConfirmation, MB_YESNO) = idYes then
          if not Exec(ResultStr, '/silent', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
            MsgBox('Erreur !!! ' #13#13 '' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
      end;
    end;
  end ;
  Result := True;
end;
v20100v
  • 696
  • 4
  • 11
  • This has nothing to do with the question asked. The question is about *foreign* application (Adobe Shockwave Player to be more specific). – TLama Nov 24 '14 at 09:27
  • one more thing: I dont want a message box, prev version should be uninstalled **automatically** if fonund – the_Ma5TeR Nov 24 '14 at 11:49
  • And one more thing: I want to do the checking only for the component named 'shockwave' (see my full iss). The checking should not be done if the user doesn't select 'shockwave' component. Not so important, but if possible add that too :) – the_Ma5TeR Nov 24 '14 at 13:15
  • Hi v20100v, your code isn't working. here is my new modified inno script containing your code: http://pastebin.com/tjywm8g5. Not a syntax error, I tested it installing old version of shockwave, and then running the new version. No dialog box, and the old version isnt uninstalled! – the_Ma5TeR Nov 24 '14 at 13:37
  • Launch regedit.exe and verify the contains of your key SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{#MyAppId}_is1 in HKLM With your defintion (#define MyAppId "Adobe Shockwave Player"), you must find an entry like this SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Shockwave Player_is1. Maybe, this entry doesn't exist in your registry. – v20100v Nov 24 '14 at 14:06