3

I'm trying to build a function for investigating MSI file properties, from my "Inno Setup" script. (I'm after the "version" in particular.)

I'm using this powershell script for reference: https://technotes.khitrenovich.com/check-msi-version-powershell/

I cannot make it work in Inno Setup. So, I've switched to Delphi. (A little better tooling etc.) And the Delphi code outputs exactly the same error as Inno Setup. (So, that's something.)

I've made this test function:

procedure Test( MsiFileName : String ) ;
var
  installer : Variant;
  database : Variant;
  sql : String;
  view : Variant;
  rec : Variant;
  dummy1 : Boolean;
  dummy2 : Integer;
  dummy3 : array of String;
begin

  MsiFileName := 'C:\Users\....\My.msi';     //Test

  CoInitialize(nil);

  installer := CreateOleObject('WindowsInstaller.Installer');
  database := installer.OpenDatabase( MsiFileName, 0 );
  sql := 'SELECT Value FROM Property WHERE Property = ''ProductVersion''';
  view := database.OpenView(sql);
  view.Execute();
  rec := view.Fetch();

  dummy1 := rec.IsNull;       //Fail!
  dummy2 := rec.DataSize;     //Fail!
  dummy3 := rec.StringData;   //Fail!

end;

I've made several tests with the msi file and the powershell script. The powershell script works and the msi file works. (It can be investigated.) But no matter what I do, I cannot make it work in Inno Setup and/or Delphi. When the code reaches the "record properties", it fails with a "Type Mismatch" exception. And I've tried with just about all possible "types". I'm not a Delphi programmer though. My guess is, that the returned "record" is somehow not a record...? The documentation for the record / Fetch can be found here: https://learn.microsoft.com/en-us/windows/win32/msi/view-fetch

Again, the code works just fine in Powershell. And I've also seen VBScripts with this working. Anyone knows what I am missing?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Illishar
  • 886
  • 1
  • 11
  • 24

1 Answers1

0

As to why stuff seems to work in powershell and not in Inno Setup / Delphi, I'm not nessesary getting any wiser. However, for the problem above I've found out that this one line will work:

string_variable := rec.StringData[1]

(And that's the important one.) This ofc was the first one, I should've tried! ... And so I did. mumble mumble

Illishar
  • 886
  • 1
  • 11
  • 24