gpt4 book ai didi

powershell - 使用Powershell在MSI中设置SummaryInformation

转载 作者:行者123 更新时间:2023-12-02 23:36:58 25 4
gpt4 key购买 nike

我正在尝试使用Powershell编辑MSI文件。我几乎可以编辑每个表,但“SummaryInformation”部分实际上不是一个与其他表相同的表。

我可以毫无问题地从这些信息中读取属性,但是我什么也不能做。

从我能够在线找到的信息中,我应该能够使用

$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()

编辑:纠正语法

关于powershell - 使用Powershell在MSI中设置SummaryInformation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53199158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com