2
votes

Since the InstallShield LE isn't supported by VS 2017 I'm trying to use Inno Setup instead.

But how can I uninstall previous installations made by InstallShield LE before installation starts using Inno Setup script.
There are multiple versions of the application installed at different users (not on the same computer).

Since the Product Code changes between versions, the GUID in Uninstall registry key can be different and because of that it is hard to find in the uninstall part of registry.

2
Inno Setup can be directly integrated into VS 2017 (as a replacement for ISLE). See this extension marketplace.visualstudio.com/… (sorry for little self promo)Slappy
I can't speak to the Inno Setup part, but the raw C++ API for finding an installed product's product code from its UpgradeCode is MsiEnumRelatedProducts.Michael Urman
FWIW, ISLE was limited in what it could do and therefore would be exceptionally easy to migrate over to Windows Installer XML. Especially if you used IsWiX.Christopher Painter

2 Answers

2
votes

You can use the code from Inno Setup: How to automatically uninstall previous installed version?

While code in the answers is for uninstalling a previous versions installed by Inno Setup, it's mostly generic enough to work with any previous uninstall system.

To make it work with InstallShield, you need to know a Product Code of the release you want to uninstall. If you need to be able to remove any release, you can lookup the Product Code of the actually installed release using the Upgrade Code. For that, you can use a WMI query:
How to find the UpgradeCode and ProductCode of an installed application in Windows 7.

In Inno Setup Pascal Script the code can be like:

const
  InstallShieldUpgradeCode = '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}';

function InitializeSetup(): Boolean;
var
  WbemLocator, WbemServices, WbemObjectSet: Variant;
  Query: string;
  ProductCode: string;
begin
  WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  WbemServices := WbemLocator.ConnectServer('.', 'root\CIMV2');
  Query :=
    'SELECT ProductCode FROM Win32_Property ' +
    'WHERE Property="UpgradeCode" AND Value="' + InstallShieldUpgradeCode + '"';
  WbemObjectSet := WbemServices.ExecQuery(Query);
  if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
  begin
    ProductCode := WbemObjectSet.ItemIndex(0).ProductCode;

    { Start uninstall here }
  end;

  Result := True;
end;

Though note that the query can take tens of seconds.

1
votes

When I wrote the sample script and the related blog post, it was quite clear that you should query the registry to detect previous installed software,

function InitializeSetup(): Boolean;
var
  oldVersion: String;
  uninstaller: String;
  ErrorCode: Integer;
begin
  if RegKeyExists(HKEY_LOCAL_MACHINE,
    'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F768F6BA-F164-4599-BC26-DCCFC2F76855}_is1') then
  begin
    RegQueryStringValue(HKEY_LOCAL_MACHINE,
      'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F768F6BA-F164-4599-BC26-DCCFC2F76855}_is1',
      'DisplayVersion', oldVersion);
    if (CompareVersion(oldVersion, '6.0.0.1004') < 0) then
    begin
      if MsgBox('Version ' + oldVersion + ' of Code Beautifier Collection is already installed. Continue to use this old version?',
        mbConfirmation, MB_YESNO) = IDYES then
      begin
        Result := False;
      end
      else
      begin
          RegQueryStringValue(HKEY_LOCAL_MACHINE,
            'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F768F6BA-F164-4599-BC26-DCCFC2F76855}_is1',
            'UninstallString', uninstaller);
          ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
          Result := True;
      end;
    end
    else
    begin
      MsgBox('Version ' + oldVersion + ' of Code Beautifier Collection is already installed. This installer will exit.',
        mbInformation, MB_OK);
      Result := False;
    end;
  end
  else
  begin
    Result := True;
  end;
end;

Your InstallShield based installer should also insert a GUID based subtree to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\, so just analyze what has been there and take necessary actions to uninstall it.

A more recent blog post can be found here.