ElkeAusBerlin
ElkeAusBerlin

Reputation: 575

Inno setup: detect installation based on product code

I want to achieve something similar to Inno setup - skip installation if other program is not installed

But I do have the msiexec product code (like D3AA40C4-9BFB-4640-88CE-EDC93A3703CC). So how to detect if another program is installed based on this product code?

Upvotes: 3

Views: 991

Answers (1)

TLama
TLama

Reputation: 76733

There is the MsiQueryProductState function for this. Here is its import with a helper function for your task:

[Code]
#IFDEF UNICODE
  #DEFINE AW "W"
#ELSE
  #DEFINE AW "A"
#ENDIF
type
  INSTALLSTATE = Longint;
const
  INSTALLSTATE_DEFAULT = 5;

function MsiQueryProductState(szProduct: string): INSTALLSTATE; 
  external 'MsiQueryProductState{#AW}@msi.dll stdcall';

function IsProductInstalled(const ProductID: string): Boolean;
begin
  Result := MsiQueryProductState(ProductID) = INSTALLSTATE_DEFAULT;
end;

And its possible usage:

if IsProductInstalled('{D3AA40C4-9BFB-4640-88CE-EDC93A3703CC}') then
  MsgBox('The product is installed.', mbInformation, MB_OK);

Upvotes: 4

Related Questions