PowerShell Windows Installer Com Object

南笙酒味 提交于 2019-12-10 17:28:05

问题


I'm trying to modify the contents of an MSI file using Powershell. To do so I create an instance of a WindowsInstaller.Installer then use $installer.OpenDatabase and $database.OpenView. Similar functionality works in VBScript and I've seen samples on-line that appear to work.

$installer = new-object -comobject "WindowsInstaller.Installer"
$database = $installer.OpenDatabase("C:\Temp\Setup.msi", 1)

For the above code, I get an error "Method invocation failed because [System.__ComObject] doesn't contain a method named 'OpenDatabase'."

$installer = new-object -comobject "WindowsInstaller.Installer"
$database = $installer.InvokeMethod("OpenDatabase","C:\Temp\Setup.msi", 1)

If I attempt to use $installer.InvokeMethod I get the same error "Method invocation failed because [System.__ComObject] doesn't contain a method named 'InvokeMethod'."

Any help would be much appreciated.

Thanks.


回答1:


See the this thread for some guidance. Basically the MSI COM object is implemented in a way that confuses PS. There is a link to a blog post discussing it in that thread.




回答2:


The originally accepted answer link, is no longer valid.

In the comments, JohnB has posted a link that has a great example of how to use the Windows Installer from Powershell.

There's also a CodePlex project that wraps a lot functionality and could be useful:
Windows Installer PowerShell Module



来源:https://stackoverflow.com/questions/450953/powershell-windows-installer-com-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!