【问题标题】:Are there any way to find the Product ID ( Product code ) for each of msi file?有没有办法找到每个 msi 文件的产品 ID(产品代码)?
【发布时间】:2021-06-20 11:41:34
【问题描述】:

会员。

我一直在努力使用 PowerShell 查找产品 ID。我在下面找到了,但是我无法理解每一行的含义。

有没有更简单的方法通过使用 powerhsell 和 cmd 来查找产品 ID,或者您能解释每一行吗?

我指的 ps1 是 Get-GuidFromMsiFile.ps1。为了从 MDM 服务器为客户端传递 Msi 文件,它使用我们用于每个 msi 文件的每个产品 ID(产品代码)。

据我调查,没有简单的方法并在下面的网站上找到。但我无法理解每一行的含义。

如果有人能解释为什么需要每一行,那就太好了(如果你能告诉我任何其他方法来查找每个 msi 文件的产品 ID(产品代码),那就太好了。

https://adamrushuk.github.io/get-product-id-guid-directly-from-msi-file/

—— 我在这里问的原因是…… —— 我正在考虑使用下面的 CSP,它的 CSP 需要产品 ID 来传递 msi 文件 但我不知道如何找到 msi 的产品 ID https://docs.microsoft.com/en-us/windows/client-management/mdm/enterprisedesktopappmanagement-csp

【问题讨论】:

标签: windows powershell windows-installer


【解决方案1】:

我下载了 Powershell 7 MSI,然后在桌面上创建了这个 script.ps1。

param(
    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()] [System.IO.FileInfo]$Path,
    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()] [ValidateSet("ProductCode", "ProductVersion", "ProductName", "Manufacturer", "ProductLanguage", "FullVersion")] [string]$Property )
Process {
    try {
        $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
        $MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
        $Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
        $View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
        $View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
        $Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
        $Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
        $MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null);
        $View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null);
        $MSIDatabase = $null;
        $View = $null;
        return $Value;
    }
    catch { Write-Warning -Message $_.Exception.Message ; break } 
} End { 
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) | Out-Null [System.GC]::Collect
}

我针对 MSI 运行脚本并获得了预期的结果。

PS C:\Users\azureuser> .\Desktop\script.ps1 -Path "C:\Users\azureuser\Downloads\PowerShell-7.1.3-win-x64.msi" -Property ProductCode
{A6307460-5CB8-47E2-91FE-A35552EA2C39}

PS C:\Users\azureuser> .\Desktop\script.ps1 -Path "C:\Users\azureuser\Downloads\PowerShell-7.1.3-win-x64.msi" -Property ProductName
PowerShell 7-x64

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多