【发布时间】:2013-12-20 21:12:35
【问题描述】:
我想使用 PowerShell 获取 MSI 摘要信息,我发现了几个用于打开 MSI 的“正常”表的脚本和代码片段。
所以这是我的问题,如何使用 PowerShell 打开摘要信息?
我附上了一些你可能会觉得有用的代码片段。
我的获取摘要信息的代码不起作用!
function Get-SummaryInformation ( [IO.FileInfo] $FilePath ){
try {
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(“OpenDatabase”, “InvokeMethod”, $Null,
$windowsInstaller, @($FilePath.FullName, 0))
$summary = $database.GetType().InvokeMember(“SummaryInformation”, “Invoke-Method”, $Null, $database, ([2]))
$MSI_Summary[1]=$summary.text
}
catch {
throw "ERROR - " + $_
}
}
获取普通 MSI 表的代码
function Get-MsiProductCode ( [IO.FileInfo] $FilePath ) {
try {
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(“OpenDatabase”, “InvokeMethod”, $Null, $windowsInstaller, @($FilePath.FullName, 0))
$q = "SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'"
$View = $database.GetType().InvokeMember(“OpenView”, “InvokeMethod”, $Null, $database, ($q))
$View.GetType().InvokeMember(“Execute”, “InvokeMethod”, $Null, $View, $Null)
$record = $View.GetType().InvokeMember(“Fetch”, “InvokeMethod”, $Null, $View, $Null)
$global:ProductCode = $record.GetType().InvokeMember(“StringData”, “GetProperty”, $Null, $record, 1)
} catch {
throw "Failed to get MSI file version the error was: {0}." -f $_
}
}
【问题讨论】:
标签: powershell windows-installer summary