获取 MSI 摘要信息

XRJ*_*JPK 5 powershell windows-installer summary

我想使用 PowerShell 获取 MSI 摘要信息,我找到了几个用于打开 MSI“正常”表的脚本和代码片段。

\n

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

\n

我附上了一些您可能会觉得有用的代码片段。

\n

我用于获取摘要信息的代码不起作用!

\n
function Get-SummaryInformation ( [IO.FileInfo] $FilePath ){\ntry {\n$windowsInstaller = New-Object -com WindowsInstaller.Installer\n\n$database = $windowsInstaller.GetType().InvokeMember(\xe2\x80\x9cOpenDatabase\xe2\x80\x9d, \xe2\x80\x9cInvokeMethod\xe2\x80\x9d, $Null,\n$windowsInstaller, @($FilePath.FullName, 0))\n$summary = $database.GetType().InvokeMember(\xe2\x80\x9cSummaryInformation\xe2\x80\x9d, \xe2\x80\x9cInvoke-Method\xe2\x80\x9d,       $Null, $database, ([2]))\n    \n$MSI_Summary[1]=$summary.text\n } \n catch {\nthrow "ERROR - " + $_\n       }\n }\n
Run Code Online (Sandbox Code Playgroud)\n

获取正常 MSI 表的代码

\n
function Get-MsiProductCode ( [IO.FileInfo] $FilePath ) {\ntry {\n$windowsInstaller = New-Object -com WindowsInstaller.Installer\n\n$database = $windowsInstaller.GetType().InvokeMember(\xe2\x80\x9cOpenDatabase\xe2\x80\x9d, \xe2\x80\x9cInvokeMethod\xe2\x80\x9d, $Null, $windowsInstaller, @($FilePath.FullName, 0))\n\n$q = "SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'"\n$View = $database.GetType().InvokeMember(\xe2\x80\x9cOpenView\xe2\x80\x9d, \xe2\x80\x9cInvokeMethod\xe2\x80\x9d, $Null, $database, ($q))\n\n$View.GetType().InvokeMember(\xe2\x80\x9cExecute\xe2\x80\x9d, \xe2\x80\x9cInvokeMethod\xe2\x80\x9d, $Null, $View, $Null)\n\n$record = $View.GetType().InvokeMember(\xe2\x80\x9cFetch\xe2\x80\x9d, \xe2\x80\x9cInvokeMethod\xe2\x80\x9d, $Null, $View, $Null)\n\n$global:ProductCode = $record.GetType().InvokeMember(\xe2\x80\x9cStringData\xe2\x80\x9d, \xe2\x80\x9cGetProperty\xe2\x80\x9d, $Null, $record, 1)\n\n} catch {\n throw "Failed to get MSI file version the error was: {0}." -f $_\n        }\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

Kei*_*ill 4

去拿一份WiX的副本。它附带了 MSI 的 .NET 包装器,使这变得更容易,例如:

\n\n
PS> Add-Type -Path \'C:\\Program Files (x86)\\WiX Toolset v3.6\\bin\\Microsoft.Deployment.WindowsInstaller.dll\'\nPS> $db = new-object Microsoft.Deployment.WindowsInstaller.Database "$pwd\\TypeScriptSetup.0.8.1.msi"\nPS> $db.SummaryInfo\n\n\nTitle          : Installation Database\nSubject        : TypeScript for Microsoft\xc2\xae Visual Studio\xc2\xae 2012\nAuthor         : Microsoft Corporation\nKeywords       : Installer\nComments       : This installer database contains the logic and data required to install TypeScript for Microsoft\xc2\xae\n                 Visual Studio\xc2\xae 2012.\nTemplate       : Intel;1033\nLastSavedBy    :\nRevisionNumber : {B41DBDE5-CF50-42FB-AF8A-13EA3003BCA1}\nCreatingApp    : Windows Installer XML (3.6.3303.0)\nLastPrintTime  : 1/1/0001 12:00:00 AM\nCreateTime     : 11/14/2012 3:38:30 PM\nLastSaveTime   : 11/14/2012 3:38:30 PM\nCodePage       : 1252\nPageCount      : 500\nWordCount      : 2\nCharacterCount : 0\nSecurity       : 2\nHandle         : 8\nIsClosed       : False\n
Run Code Online (Sandbox Code Playgroud)\n