[CODE] Check whether a program is installed & uninstall it before continuing the setup

Inno Setup Discussion
Post Reply
User avatar
Posts: 62
Joined: Wed Apr 13, 2016 9:15 am
Location: $omewhere in the Un!verse

[CODE] Check whether a program is installed & uninstall it before continuing the setup

Post by niTe_RiDeR_Pr0 » Mon Apr 18, 2016 5:52 am

This is an inno setup code to check whether a specified program is already installed in the PC, & if found, then uninstall it (when setup is started).

Imagine a scenario: You are installing a program through inno setup's [Run] function, for eg. adobe shockwave player msi, but an older version of the program is already installed & the installer cant overwrite it/cannot find it, so the newer version cannot be installed. Inno Setup does not have this function built-in, but there is another solution for this.

First go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ in your Registry Editor (Open run by pressing Win+R from keyboard > type "regedit.exe" & press enter) and find out that app's name (or) ID (using search function in registry editor, or you can find it manually too by going through all the subkeys), then
Use this code:

Code: Select all

#define MyAppId "Your App ID (the registry subkey)"
// Add the above line at the beginning of the inno script.

function InitializeSetup(): Boolean;
  // Check if the application is already install
  // MsgBox('MyAppId = ' + '{#MyAppId}', mbInformation, mb_Ok);
    If RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}', 'UninstallString', ResultStr) then begin
      If ResultStr<>'' then begin
          if not Exec(ResultStr, 'parameters for the uninstaller.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
            MsgBox('Error !' #13#13 '' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  end ;
  Result := True;
Cheers ;)
Image Image

Post Reply