msiproduct.iss 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. [Code]
  2. #ifdef UNICODE
  3. #define AW "W"
  4. #else
  5. #define AW "A"
  6. #endif
  7. type
  8. INSTALLSTATE = Longint;
  9. const
  10. INSTALLSTATE_INVALIDARG = -2; // An invalid parameter was passed to the function.
  11. INSTALLSTATE_UNKNOWN = -1; // The product is neither advertised or installed.
  12. INSTALLSTATE_ADVERTISED = 1; // The product is advertised but not installed.
  13. INSTALLSTATE_ABSENT = 2; // The product is installed for a different user.
  14. INSTALLSTATE_DEFAULT = 5; // The product is installed for the current user.
  15. function MsiQueryProductState(szProduct: string): INSTALLSTATE;
  16. external 'MsiQueryProductState{#AW}@msi.dll stdcall';
  17. function MsiEnumRelatedProducts(szUpgradeCode: string; nReserved: dword; nIndex: dword; szProductCode: string): integer;
  18. external 'MsiEnumRelatedProducts{#AW}@msi.dll stdcall';
  19. function MsiGetProductInfo(szProductCode: string; szProperty: string; szValue: string; var nvalueSize: dword): integer;
  20. external 'MsiGetProductInfo{#AW}@msi.dll stdcall';
  21. function msiproduct(productID: string): boolean;
  22. begin
  23. Result := MsiQueryProductState(productID) = INSTALLSTATE_DEFAULT;
  24. end;
  25. function msiproductupgrade(upgradeCode: string; minVersion: string): boolean;
  26. var
  27. productCode, version: string;
  28. valueSize: dword;
  29. begin
  30. SetLength(productCode, 39);
  31. Result := false;
  32. if (MsiEnumRelatedProducts(upgradeCode, 0, 0, productCode) = 0) then begin
  33. SetLength(version, 39);
  34. valueSize := Length(version);
  35. if (MsiGetProductInfo(productCode, 'VersionString', version, valueSize) = 0) then begin
  36. Result := compareversion(version, minVersion) >= 0;
  37. end;
  38. end;
  39. end;
  40. [Setup]