gpt4 book ai didi

powershell - 获取 MSI 摘要信息

转载 作者:行者123 更新时间:2023-12-02 22:37:38 26 4
gpt4 key购买 nike

我想使用 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 $_
}
}

最佳答案

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

关于powershell - 获取 MSI 摘要信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20374421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com