It is required in the Inno Setup script to get the version of the product already installed by ProductUpgradeCode and display it.

You can get product id by ProductUpgradeCode using MsiEnumRelatedProducts .

Next, the product version can be using MsiGetProductInfo .

 #ifdef UNICODE #define AW "W" #else #define AW "A" #endif const ERROR_SUCCESS = $00000000; ERROR_NOT_ENOUGH_MEMORY = $00000008; ERROR_INVALID_PARAMETER = $00000057; ERROR_NO_MORE_ITEMS = $00000103; ERROR_BAD_CONFIGURATION = $0000064A; function MsiEnumRelatedProducts(lpUpgradeCode: string; dwReserved: DWORD; iProductIndex: DWORD; lpProductBuf: string): UINT; external 'MsiEnumRelatedProducts{#AW}@msi.dll stdcall'; function MsiGetProductInfo(szProduct: string; szProperty: string; lpValueBuf: string; pcchValueBuf: DWORD): UINT; external 'MsiGetProductInfo{#AW}@msi.dll stdcall'; function CheckPreviousProductInstance(upgradeCode: string; var previousVersion: string): Boolean; var i: Integer; productBuf: string; versionBuf: string; pcchValueBuf: DWORD; resultCode: UINT; begin Result := True; i := 0; SetLength(productBuf, 39); if MsiEnumRelatedProducts(upgradeCode, 0, i, productBuf) <> ERROR_SUCCESS then begin result := false; exit; end; MsgBox(productBuf, mbInformation, MB_OK); resultCode := MsiGetProductInfo(productBuf, 'INSTALLPROPERTY_VERSIONSTRING', versionBuf, pcchValueBuf); MsgBox(IntToStr(Integer(resultCode)), mbInformation, MB_OK); if MsiGetProductInfo(productBuf, 'INSTALLPROPERTY_VERSIONSTRING', versionBuf, pcchValueBuf) <> ERROR_SUCCESS then begin result := false; exit; end; MsgBox(versionBuf, mbInformation, MB_OK); MsgBox(IntToStr(Integer(pcchValueBuf)), mbInformation, MB_OK); result := true; end; 

MsiGetProductInfo returns $ 0000648.

How to do right?

    1 answer 1

    For Inno Setup Unicode it turned out like this:

     const // Full list: https://msdn.microsoft.com/en-us/library/windows/desktop/aa376931(v=vs.85).aspx ERROR_SUCCESS = 0; INSTALLPROPERTY_VERSIONSTRING = 'VersionString'; function MsiEnumRelatedProducts(lpUpgradeCode: string; dwReserved: DWORD; iProductIndex: DWORD; lpProductBuf: string): UINT; external 'MsiEnumRelatedProductsW@msi.dll stdcall'; function MsiGetProductInfo(szProduct: string; szProperty: String; lpValueBuf: String; var pcchValueBuf: DWORD): UINT; external 'MsiGetProductInfoW@msi.dll stdcall'; function GetPreviousProduct(UpgradeCode: string; var PreviousProductId: string; var PreviousProductVersion: string): Boolean; var ProductBuf: string; VersionBuf: String; PcchValueBuf: DWORD; begin SetLength(ProductBuf, 39); if MsiEnumRelatedProducts(upgradeCode, 0, 0, ProductBuf) <> ERROR_SUCCESS then begin PreviousProductId := ''; PreviousProductVersion := ''; Result := false; exit; end; SetLength(VersionBuf, 255); PcchValueBuf := Length(VersionBuf); if MsiGetProductInfo(ProductBuf, INSTALLPROPERTY_VERSIONSTRING, VersionBuf, PcchValueBuf) <> ERROR_SUCCESS then begin MsgBox('The VersionString is not received.', mbCriticalError, MB_OK); Abort(); exit; end; SetLength(VersionBuf, PcchValueBuf); PreviousProductId := ProductBuf; PreviousProductVersion := VersionBuf; Result := true; end;