mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Fixes MSI package reader on Windows 2012 R2
This commit is contained in:
parent
a4630f8d8f
commit
ed8e109fad
1 changed files with 15 additions and 8 deletions
|
|
@ -25,21 +25,25 @@ function Read-IcingaMSIMetadata()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$InstallerInstance = New-Object -ComObject 'WindowsInstaller.Installer';
|
$InstallerInstance = New-Object -ComObject 'WindowsInstaller.Installer';
|
||||||
$MSIPackage = $InstallerInstance.OpenDatabase($File, 0);
|
#$MSIPackage = $InstallerInstance.OpenDatabase($File, 0); # Not Working on Windows 2012 R2
|
||||||
|
$MSIPackage = $InstallerInstance.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $Null, $InstallerInstance, @($File, 0));
|
||||||
|
|
||||||
foreach ($PackageInfo in $MSIObjects) {
|
foreach ($PackageInfo in $MSIObjects) {
|
||||||
$MSIQuery = [string]::Format(
|
$MSIQuery = [string]::Format(
|
||||||
"SELECT `Value` FROM `Property` WHERE `Property` = '{0}'",
|
"SELECT `Value` FROM `Property` WHERE `Property` = '{0}'",
|
||||||
$PackageInfo
|
$PackageInfo
|
||||||
);
|
);
|
||||||
$MSIDb = $MSIPackage.OpenView($MSIQuery);
|
#$MSIDb = $MSIPackage.OpenView($MSIQuery); # Not Working on Windows 2012 R2
|
||||||
|
$MSIDb = $MSIPackage.GetType().InvokeMember('OpenView', 'InvokeMethod', $Null, $MSIPackage, $MSIQuery);
|
||||||
|
|
||||||
if ($null -eq $MSIDb) {
|
if ($null -eq $MSIDb) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$MSIDb.Execute();
|
#$MSIDb.Execute(); # Not Working on Windows 2012 R2
|
||||||
$MSITable = $MSIDb.Fetch();
|
$MSIDb.GetType().InvokeMember('Execute', 'InvokeMethod', $Null, $MSIDb, $Null);
|
||||||
|
#$MSITable = $MSIDb.Fetch(); # Not Working on Windows 2012 R2
|
||||||
|
$MSITable = $MSIDb.GetType().InvokeMember('Fetch' , 'InvokeMethod', $Null, $MSIDb, $Null);
|
||||||
|
|
||||||
if ($null -eq $MSITable) {
|
if ($null -eq $MSITable) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -47,13 +51,16 @@ function Read-IcingaMSIMetadata()
|
||||||
|
|
||||||
$MSIPackageData[$PackageInfo] = $MSITable.GetType().InvokeMember('StringData', 'GetProperty', $null, $MSITable, 1);
|
$MSIPackageData[$PackageInfo] = $MSITable.GetType().InvokeMember('StringData', 'GetProperty', $null, $MSITable, 1);
|
||||||
|
|
||||||
$MSIDb.Close();
|
#$MSIDb.Close(); # Not Working on Windows 2012 R2
|
||||||
$MSIPackage.Commit();
|
$MSIDb.GetType().InvokeMember('Close', 'InvokeMethod', $null, $MSIDb, $null);
|
||||||
|
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($MSIDb));
|
||||||
|
$MSIDb = $null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$MSIPackage.Commit();
|
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($MSIPackage));
|
||||||
$MSIPackage = $null;
|
|
||||||
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($InstallerInstance));
|
[void]([System.Runtime.InteropServices.Marshal]::ReleaseComObject($InstallerInstance));
|
||||||
|
$MSIPackage = $null;
|
||||||
|
$InstallerInstance = $null;
|
||||||
|
|
||||||
if ($AgentFile.Name.Contains('x86_64')) {
|
if ($AgentFile.Name.Contains('x86_64')) {
|
||||||
$MSIPackageData.Add('Architecture', 'x64')
|
$MSIPackageData.Add('Architecture', 'x64')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue