Read msi file in perl

Viewed 209

I would like to read an msi file. I use the library Win32 :: MSI :: HighLevel but this one sends me undef all the time.

My code:

use strict;
use warnings FATAL => 'all';
use Win32::MSI::DB qw(Win32::MSI::DB::MSIDBOPEN_READONLY);
use Win32::MSI::HighLevel;
use Data::Dumper;
my $msi = Win32::MSI::HighLevel->new (-file => "Firefox.msi", -mode => $Win32::MSI::DB::MSIDBOPEN_READONLY) or die "error $!";
my $productCode = $msi->getProductCode;
my $product = $msi->getProduct;

print Dumper  $productCode;

The $product returns ': - ' and $productCode is undef .

I have checked the information of msi file in the Windows file properties and verified the information are inside. I have tried the code with another msi file and I have the same problem.

2 Answers

The ProductCode of an MSI file is in a table called Properties inside the MSI file, which is a relational database. It's not a file property. This post should help:

PowerShell: Get the MSI product code out of a MSI file without installing?

because it outlines the various calls that need to be made, which are basically to open the database, do an OpenView with the SQL query ""SELECT Value FROM Property WHERE Property = 'ProductCode' and so on, and similar here:

https://codereview.stackexchange.com/questions/143304/get-productcode-from-msi-file-using-dtf-in-c

I find the solution. I add call at "populateTable" function, so the code is:

use strict;
use warnings FATAL => 'all';
use Win32::MSI::DB qw(Win32::MSI::DB::MSIDBOPEN_READONLY);
use Win32::MSI::HighLevel;
use Data::Dumper;
my $msi = Win32::MSI::HighLevel->new (-file => "Firefox.msi", -mode => $Win32::MSI::DB::MSIDBOPEN_READONLY) or die "error $!";
$msi->populateTable();
my $productCode = $msi->getProductCode;
my $product = $msi->getProduct;

print Dumper  $productCode;
Related