PowerShell Windows 安装程序 Com 对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/450953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PowerShell Windows Installer Com Object
提问by MattH
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.
我正在尝试使用 Powershell 修改 MSI 文件的内容。为此,我创建了一个 WindowsInstaller.Installer 实例,然后使用 $installer.OpenDatabase 和 $database.OpenView。类似的功能在 VBScript 中也可以使用,而且我在网上看到过一些看起来可以正常工作的示例。
$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'."
对于上述代码,我收到错误消息“方法调用失败,因为 [System.__ComObject] 不包含名为‘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'."
如果我尝试使用 $installer.InvokeMethod,我会收到同样的错误“方法调用失败,因为 [System.__ComObject] 不包含名为‘InvokeMethod’的方法。”
Any help would be much appreciated.
任何帮助将非常感激。
Thanks.
谢谢。
采纳答案by EBGreen
回答by Ralph Willgoss
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.
在评论中,JohnB 发布了一个链接,其中有一个很好的示例,说明如何从 Powershell 使用 Windows 安装程序。
There's also a CodePlex project that wraps a lot functionality and could be useful:
Windows Installer PowerShell Module
还有一个 CodePlex 项目,它包含了很多功能并且可能很有用:
Windows Installer PowerShell Module