获取MSI摘要信息

时间:2013-12-04 11:41:52

标签: powershell windows-installer summary

我想通过PowerShell获取MSI摘要信息我找到了几个脚本和代码snippits,用于选择MSI的“普通”表。

以下是我的问题,如何使用PowerShell打开摘要信息?

我附上了一些您可能觉得有用的代码信息。

我的代码获取Summarary信息不起作用!

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 - " + $_
       }
 }

gettin普通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 $_
        }
  }

2 个答案:

答案 0 :(得分:2)

去拿一份WiX。它附带了一个用于MSI的.NET包装器,可以使这更容易,例如:

PS> Add-Type -Path 'C:\Program Files (x86)\WiX Toolset v3.6\bin\Microsoft.Deployment.WindowsInstaller.dll'
PS> $db = new-object Microsoft.Deployment.WindowsInstaller.Database "$pwd\TypeScriptSetup.0.8.1.msi"
PS> $db.SummaryInfo


Title          : Installation Database
Subject        : TypeScript for Microsoft® Visual Studio® 2012
Author         : Microsoft Corporation
Keywords       : Installer
Comments       : This installer database contains the logic and data required to install TypeScript for Microsoft®
                 Visual Studio® 2012.
Template       : Intel;1033
LastSavedBy    :
RevisionNumber : {B41DBDE5-CF50-42FB-AF8A-13EA3003BCA1}
CreatingApp    : Windows Installer XML (3.6.3303.0)
LastPrintTime  : 1/1/0001 12:00:00 AM
CreateTime     : 11/14/2012 3:38:30 PM
LastSaveTime   : 11/14/2012 3:38:30 PM
CodePage       : 1252
PageCount      : 500
WordCount      : 2
CharacterCount : 0
Security       : 2
Handle         : 8
IsClosed       : False

答案 1 :(得分:0)

$Installer = New-Object -com WindowsInstaller.Installer
$Database = $Installer.GetType().InvokeMember(“OpenDatabase”, “InvokeMethod”, $Null, $Installer, $($MsiFile,0))
$SummaryInfo = $Database.GetType().InvokeMember(“SummaryInformation”, “GetProperty”,$Null , $Database, $Null)
$PropertyCount = $SummaryInfo.GetType().InvokeMember(“PropertyCount”, “GetProperty”, $Null, $SummaryInfo, $Null)

(0..$PropertyCount) | ForEach { Write-Host $_ $SummaryInfo.GetType().InvokeMember(“Property”, “GetProperty”, $Null, $SummaryInfo, $_) }


0 
1 1252
2 Installation Database
3 SlimDX Runtime .NET 4.0 x86 (January 2012)
4 SlimDX Group
5 Installer
6 This installer database contains the logic and data required to install SlimDX Runtime .NET 4.0 x86 (January 2012).
7 Intel;1033
8 
9 {98E616FB-251F-4FB4-A3AC-4773096EB5B5}
10 
11 
12 05.02.2012 1:22:04
13 05.02.2012 1:22:04
14 300