使用 Powershell 在 msi 中设置 SummaryInformation

Set SummaryInformation in an msi using Powershell

我正在尝试使用 powershell 编辑 msi 文件。我几乎可以编辑每个 table,但 "SummaryInformation" 部分并不是像其他部分那样真正的 table。

我可以毫无问题地从此信息中读取属性,但我无法设置任何内容。

根据我在网上找到的信息,我应该可以使用

来设置它
$SummaryInfo.GetType().InvokeMember("Property", "SetProperty”, $null, $SummaryInfo,@(3,'test'))

但是当我尝试这个时,我得到了一个非常奇怪的错误,

Exception calling "InvokeMember" with "5" argument(s): "Property,Pid"

只有当我将“@(3,'test')”数组指定为@(int,string) 时,我才会收到此错误,否则我会收到类型不匹配错误。这让我相信我接近正确的解决方案。

如有任何帮助,我们将不胜感激。

下面是我认为应该有效的代码。

$MSIPATH = "Path To MSI File"

$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer 

$MSIDatabase = $windowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $windowsInstaller, @($MSIPATH, 1)) 

$SummaryInfo = $MSIDatabase.GetType().InvokeMember(“SummaryInformation”, “GetProperty”,$Null , $MSIDatabase, $Null)

#get the porperty that I want to set
$SummaryInfo.GetType().InvokeMember(“Property”, “GetProperty”, $null, $SummaryInfo, @(3))

#Attempt to set the property this fails
$SummaryInfo.GetType().InvokeMember("Property", "SetProperty”, $null, $SummaryInfo,@(3,'test'))

感谢 mklement0,我找到了解决方案

代码是这样的

$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer 
$MSI = $windowsInstaller.OpenDatabase("Path to MSI", 1)

$SummaryInfo = $MSI.SummaryInformation(4)

$SummaryInfo.Property(3) = "Test"
$SummaryInfo.Persist()
$MSI.Commit()

有时候你只是需要有人告诉你你很笨。

感谢 mklement0 我找到了解决方案

我无法像编辑其他表格那样使用相同的方法。但是已经通过使用直接调用找到了解决方案。

代码是这样的

$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer 
$MSI = $windowsInstaller.OpenDatabase("Path to MSI", 1)

$SummaryInfo = $MSI.SummaryInformation(4)

$SummaryInfo.Property(3) = "Test"
$SummaryInfo.Persist()
$MSI.Commit()

编辑:纠正语法