我正在创建PowerShell脚本,以便通过创建新组件,功能和属性从MSI生成MST。在创建组件时,我遇到了一个问题。以下是我的代码段和错误消息。
代码:
$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$database1 = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase",
"InvokeMethod",
$Null,
$windowsInstaller,
@($database1Path, $msiOpenDatabaseModeReadOnly)
)
#open 'backup' MSI in transact mode
$database2 = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase",
"InvokeMethod",
$Null,
$windowsInstaller,
@($database2Path, $msiOpenDatabaseModeTransact)
)
$query2 = "INSERT INTO ``Component`` (``Component``,``ComponentId``,``Directory_``,``Attributes``,``Condition``,``KeyPath``,``Full Directory``) VALUES ('My_Branding','{B960EF8B-A4AC-447C-91F3-C19CCAC3899E}','INSTALLDIR','4',' ',' ','Windows\System32\Macromed\Flash')"
$View2 = $database2.GetType().InvokeMember("OpenView","InvokeMethod",$Null,$database2,($query2))
$View2.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View2, $Null)
$View2.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View2, $Null)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($View2) | Out-Null
#Commit the changes to our backup database
$database2.GetType().InvokeMember("Commit", "InvokeMethod", $Null, $database2, $Null)
#Generate a transform (the difference between our original MSI and our Backup MSI)
$transformSuccess = $database2.GetType().InvokeMember(
"GenerateTransform",
"InvokeMethod",
$Null,
$database2,
@($database1,$MSTPath)
)
#Create a Summary Information Stream for the MST
$transformSummarySuccess = $database2.GetType().InvokeMember(
"CreateTransformSummaryInfo",
"InvokeMethod",
$Null,
$database2,
@($database1,$MSTPath, $msiTransformErrorNone, $msiTransformValidationNone)
)
#Release objects from memory
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($database1) | Out-Null
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($database2) | Out-Null
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($windowsInstaller) | Out-Null
错误讯息:
异常调用" InvokeMember"用" 5"参数:" OpenView,Sql" 在C:\ Jagan \ Jagan \ Scripts \ New folder \ MSI \ Untitled5.ps1:65 char:1 + $ View2 = $ database2.GetType()。InvokeMember(" OpenView"," InvokeMethod",$ Null,$ data ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:COMException异常调用" InvokeMember"用" 5"参数:"已经存在的COM对象 与其基础RCW分离不能使用。"在 C:\ Jagan \ Jagan \ Scripts \ New folder \ MSI \ Untitled5.ps1:66 char:1 + $ View2.GetType()。InvokeMember(" Execute"," InvokeMethod",$ Null,$ View2,$ Null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:InvalidComObjectException异常调用" InvokeMember"用" 5"参数:"已经存在的COM对象 与其基础RCW分离不能使用。"在 C:\ Jagan \ Jagan \ Scripts \ New folder \ MSI \ Untitled5.ps1:67 char:1 + $ View2.GetType()。InvokeMember(" Close"," InvokeMethod",$ Null,$ View2,$ Null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:InvalidComObjectException