Author Posts

January 1, 2012 at 12:00 am

by mac-duff at 2012-11-28 07:06:04

Hi there,

I am facing problems by executing one function of the windows installer


function Invoke-Method ($Object, $MethodName, $ArgumentList) {
return $Object.GetType().InvokeMember($MethodName, 'Public, Instance, InvokeMethod', $null, $Object, $ArgumentList)
}
$installer = New-Object -ComObject WindowsInstaller.Installer
$database1 = Invoke-Method $installer OpenDatabase @($MSI_Path, $msiOpenDatabaseModeReadOnly)
$database3 = Invoke-Method $installer OpenDatabase @($MSI_file3, $msiOpenDatabaseModeReadOnly)

Invoke-Method $database3 GenerateTransform @($database1, $MST_Path)

The problem is the GenerateTransform statement where all the time I get this error:

Exception calling "InvokeMember" with "5" argument(s): "GenerateTransform,ReferenceDatabase,TransformFile"
At C:\Users\shadmin\Desktop\mod.ps1:4 char:39
+ return $Object.GetType().InvokeMember < <<< ($MethodName, 'Public, Instance, InvokeMethod', $null, $Object, $ArgumentList)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation

and I really dont know where is the error because I call it exactly like MS does in the VBS which also works:

Dim different:different = Database2.GenerateTransform(Database1, transform) : CheckError

any ideas, thanks
Stephan

by DonJ at 2012-11-28 08:39:11

Have you tried not using Invoke-Method?

$database3.GenerateTransform($database1,$MST_Path)

?

The issue is in the syntax of Invoke-Method, but that cmdlet is completely unnecessary, here. You should be able to use a much more VBS-like syntax.

by mac-duff at 2012-11-28 22:58:22

than I get the message that the method does not exist, but either I cant do it like this with opendatabase, so I think it is a normal behavior.
I am also pretty sure that this method exist because it is part of the WindowsInstaller object

Edit:
When I execute it like this:

Invoke-Method $database3 GenerateTransform $database1 $transform

I dont get the above error but neither a transform file....

by DonJ at 2012-11-29 07:10:18

It might just not like being called through PowerShell > Framework > Interop > COM. Sorry – this isn't one I have much experience with, so basically guessing :(.

by mac-duff at 2012-12-20 02:10:31

Hi,
well the problem was how I opened the DB also when I still dont understand the difference


$database = $Installer.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $Installer, @($MSI_file2, 0))