3

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.

simbabque
  • 53,749
  • 8
  • 73
  • 136
Oneill
  • 339
  • 2
  • 17
  • When you look at the file properties, does it show that information in the details? (I don't remember what those tabs and things are called, and I don't have access to a Windows machine, but I think you should be able to see this info). Maybe it's really just missing from the file. Try a different file and see if the same code works. – simbabque Nov 14 '17 at 09:24
  • 1
    Thanks for your answer. I have tried to read the information of msi file and the informations are inside. I have tried the code with an other msi file and I have the same problem. – Oneill Nov 14 '17 at 09:54
  • 1
    I have edited. Thanks for your time. – Oneill Nov 14 '17 at 10:10

2 Answers2

0

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

PhilDW
  • 20,260
  • 1
  • 18
  • 28
0

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;
Oneill
  • 339
  • 2
  • 17