Skip to content

Commit aa76406

Browse files
authored
Merge pull request #325 from Icinga:fix/msi_reader_windows2012r2
Fix: MSI package reader not working on Windows 2012 R2 On Windows 2012 R2, the current implementation for `Read-IcingaMSIMetadata` is not working, as we require to do it on a more complicated way.
2 parents a4630f8 + ed8e109 commit aa76406

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/core/repository/Read-IcingaMSIMetadata.psm1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,42 @@ function Read-IcingaMSIMetadata()
2525

2626
try {
2727
$InstallerInstance = New-Object -ComObject 'WindowsInstaller.Installer';
28-
$MSIPackage = $InstallerInstance.OpenDatabase($File, 0);
28+
#$MSIPackage = $InstallerInstance.OpenDatabase($File, 0); # Not Working on Windows 2012 R2
29+
$MSIPackage = $InstallerInstance.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $Null, $InstallerInstance, @($File, 0));
2930

3031
foreach ($PackageInfo in $MSIObjects) {
3132
$MSIQuery = [string]::Format(
3233
"SELECT `Value` FROM `Property` WHERE `Property` = '{0}'",
3334
$PackageInfo
3435
);
35-
$MSIDb = $MSIPackage.OpenView($MSIQuery);
36+
#$MSIDb = $MSIPackage.OpenView($MSIQuery); # Not Working on Windows 2012 R2
37+
$MSIDb = $MSIPackage.GetType().InvokeMember('OpenView', 'InvokeMethod', $Null, $MSIPackage, $MSIQuery);
3638

3739
if ($null -eq $MSIDb) {
3840
continue;
3941
}
4042

41-
$MSIDb.Execute();
42-
$MSITable = $MSIDb.Fetch();
43+
#$MSIDb.Execute(); # Not Working on Windows 2012 R2
44+
$MSIDb.GetType().InvokeMember('Execute', 'InvokeMethod', $Null, $MSIDb, $Null);
45+
#$MSITable = $MSIDb.Fetch(); # Not Working on Windows 2012 R2
46+
$MSITable = $MSIDb.GetType().InvokeMember('Fetch' , 'InvokeMethod', $Null, $MSIDb, $Null);
4347

4448
if ($null -eq $MSITable) {
4549
continue;
4650
}
4751

4852
$MSIPackageData[$PackageInfo] = $MSITable.GetType().InvokeMember('StringData', 'GetProperty', $null, $MSITable, 1);
4953

50-
$MSIDb.Close();
51-
$MSIPackage.Commit();
54+
#$MSIDb.Close(); # Not Working on Windows 2012 R2
55+
$MSIDb.GetType().InvokeMember('Close', 'InvokeMethod', $null, $MSIDb, $null);
56+
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($MSIDb));
57+
$MSIDb = $null;
5258
}
5359

54-
$MSIPackage.Commit();
55-
$MSIPackage = $null;
60+
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($MSIPackage));
5661
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($InstallerInstance));
62+
$MSIPackage = $null;
63+
$InstallerInstance = $null;
5764

5865
if ($AgentFile.Name.Contains('x86_64')) {
5966
$MSIPackageData.Add('Architecture', 'x64')

0 commit comments

Comments
 (0)