I'm am trying to accomplish this in Powershell, I've found it to very difficult to do. This is the closest bit of code I've found that does something similar. I've also found this example which is similar but in VBScript. I've compiled all this plus hours of googling into this:
$com_object = New-Object -com WindowsInstaller.Installer
[int]$msiOpenDatabaseMode = 0
$database = $com_object.GetType().InvokeMember(
"OpenDatabase",
"InvokeMethod",
$Null,
$com_object,
@("C:\XXX.msi", $msiOpenDatabaseMode)
)
$View = $database.GetType().InvokeMember('OpenView', 'InvokeMethod', $null, $database,
("INSERT INTO Property (Property, Value) VALUES ('REBOOT', 'Force')"))
$View.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $View, $null) | Out-Null
$View.GetType().InvokeMember('Close', 'InvokeMethod', $null, $View, $null) | Out-Null
However I get the following when I run it:
Exception calling "InvokeMember" with "5" argument(s): "Execute,Params" At C:\XXX\Example.PS1:15 char:5 $View.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $V ...
CategoryInfo : NotSpecified: (:) [], MethodInvocationException FullyQualifiedErrorId : COMException
And I can't figure out why, does anyone have a idea why this won't run? My real issue with this is that I can't see the root of the issue, all the COMExceptions don't seem to return any real information, it makes figuring out why COM invocations are failing extremely difficult, is there a better way of doing that too?