【问题标题】:Getting MSI Summary Information获取 MSI 摘要信息
【发布时间】: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


    【解决方案1】:

    去取一份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
    

    【讨论】:

      【解决方案2】:
      $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
      

      【讨论】:

      • 纯代码答案没有多大用处。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 2020-07-21
      • 1970-01-01
      • 2012-12-30
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多