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

Inno Setup Discussion
User avatar
Posts: 62
Joined: Wed Apr 13, 2016 9:15 am
Location: $omewhere in the Un!verse
Has thanked: 34 times
Been thanked: 61 times

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

Postby 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

Return to “Inno Setup”

Who is online

Users browsing this forum: No registered users and 1 guest