Search code examples
visual-studio-2017inno-setupinstallshieldsetup-project

In Inno Setup installer, uninstall installation made by InstallShield LE


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.


Solution

  • 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.