如何找到已安装的MSI文件的升级代码? [英] How can I find the Upgrade Code for an installed MSI file?

查看:278
本文介绍了如何找到已安装的MSI文件的升级代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,可能会需要检索已部署软件包的MSI升级代码.

In certain cases the need to retrieve MSI upgrade codes for deployed packages can arise.

常见方案:

  • 我接管了其他人的MSI项目,我需要确定已在狂野使用的以前版本使用了哪些升级代码.这是处理升级方案所必需的. 我在任何地方都没有发行版本的存档.
  • 在开发过程中,我不小心多次更改了WiX软件包的升级代码,并且需要狂野地"找到所有升级代码版本. 我不知道各个版本之间的升级代码应该保持稳定.
  • I took over someone else's MSI project, and I need to determine what upgrade codes were used for previous versions that are already in the wild. This is necessary to handle upgrade scenarios. I have no archive of releases anywhere.
  • I accidentally changed the upgrade code for my WiX package several times during development and I need to find all Upgrade Code versions "in the wild". I was not aware that Upgrade Codes should remain stable between versions.

这是一个问/答样式问题.

这个问题曾以各种形式出现过,但这不是重复的.我正在发布一种使用 MSI主自动化界面(或严格来说是WMI)的方法. 应该比以前答案中基于注册表的方法更可靠.该答案还试图总结其他检索方法.

This question has come up before in various incarnations, but this is not a duplicate. I am posting a way to do it that uses the main MSI automation interface (or strictly speaking WMI). It should be more reliable than registry based approaches from previous answers. This answers also tries to summarize other retrieval approaches.

推荐答案

MSI升级代码检索(通过PowerShell/WMI)

正在卸载? : Via Upgrade Code, Via Product Code, Via Product Name, etc...

下面的 PowerShell脚本应检索安装在您的计算机上的所有相关的产品代码升级代码产品名称机器(表输出).

The PowerShell script below should retrieve all related product codes, upgrade codes and product names installed on your machine (table output).

输出(以下完整脚本)的屏幕截图:

Screenshot of output (full script below):

这些是直接在相关计算机上的 Windows Installer数据库中的实时值.无需任何转换或解释.我们正在使用正确的API.

These are the real, live values directly from the Windows Installer database on the machine in question. There is no need for any conversion or interpretation. We are going through the proper APIs.

技术注释!:请注意,直接在原始MSI文件(属性表)或WiX源文件中检查属性可能与实际安装的值不匹配,因为可以在安装时通过转换(以下更多信息)-或在命令行中指定的属性值.故事的寓意是:在可能的情况下直接从系统中检索属性值.

Technical note!: Be aware that checking properties directly in your original MSI file (property table) or WiX source file, may not match actual installed values since properties can be overridden at install time via transforms (more info below) - or property values specified at the command line. The moral of the story: retrieve property values directly from the system when you can.

快速免责声明:在极少数情况下,运行脚本可能会触发Windows Installer的自我修复.在免责声明"部分中了解更多信息. 以下.只是潜在的麻烦,但请阅读免责声明.

Quick disclaimer: In rare cases running the script can trigger a Windows Installer self-repair. Read more in "disclaimer section" below. Just a potential nuisance, but read the disclaimer please.

作为题外话,还有一个单行PowerShell命令,该命令将仅检索产品代码和升级代码-不包括程序包名称.对于某些用户,这实际上可能就足够了(不过,我建议使用下面的完整脚本).下面的部分中有此单线输出的屏幕截图. 注意:此命令的显示速度比较大的脚本快得多( )(值"字段是升级代码).另请注意:据我所知,没有关联升级代码的产品代码将不会显示-它们将在较大的脚本中显示:

As a digression, there is also a one-line PowerShell command which will retrieve product codes and upgrade codes only - without the package name included. This might actually suffice for some users (I would recommend the full script below however). There is a screenshot of the output of this one-liner in a section below. Note: this command appears a lot faster than the larger script (the "Value" field is the upgrade code). Also note: product codes without associated upgrade codes will not show up as far as I can tell - they will in the larger script:

gwmi -Query "SELECT ProductCode,Value FROM Win32_Property WHERE Property='UpgradeCode'" | Format-Table ProductCode,Value

要在下面运行完整的PowerShell脚本:

  1. 启动PowerShell (按住Windows键,点按R,释放Windows键,键入"powershell",然后按OK或按Enter键.)
  2. >
  3. 完整复制下面的脚本,然后只需在PowerShell窗口内右键单击.
  4. 这应该启动脚本,并且要花相当长的时间才能运行.
  5. 请报告任何问题.我不是PowerShell专家-我不是部署专家,也不是编码人员,但是脚本应该可以完成工作.
  6. 性能说明:我只获得了整个 Win32_Product WMI对象
    • 樱桃的采摘特性实际上使它变慢了一点(VBScript测试).
    • 我想我们仍然需要获取所有行,而樱桃采摘列只是额外的工作?
    • 对于 Win32_Property ,我们同时过滤行和列(升级代码只是许多行类型之一).为慢速操作做好准备,WMI非常慢.
  1. Launch PowerShell (hold down the Windows key, tap R, release the Windows key, type in "powershell" and press OK or hit enter).
  2. Copy the script below in its entirety, and then just right click inside the PowerShell window.
  3. This should start the script, and it will take quite a while to run.
  4. Please report any problems. I am no PowerShell expert - I am a deployment specialist not a coder, but the script should do the job.
  5. Performance note: I just get the whole Win32_Product WMI object
    • Cherry picking properties seemed to actually make it marginally slower (VBScript test).
    • I guess we need to get all rows anyway, and cherry picking columns is just extra lifting?
    • For Win32_Property we filter both rows and columns (upgrade code is just one of many row-types). Be prepared for a slow operation, WMI is very slow.

$wmipackages = Get-WmiObject -Class win32_product
$wmiproperties = gwmi -Query "SELECT ProductCode,Value FROM Win32_Property WHERE Property='UpgradeCode'"
$packageinfo = New-Object System.Data.Datatable
[void]$packageinfo.Columns.Add("Name")
[void]$packageinfo.Columns.Add("ProductCode")
[void]$packageinfo.Columns.Add("UpgradeCode")

foreach ($package in $wmipackages) 
{
    $foundupgradecode = $false # Assume no upgrade code is found

    foreach ($property in $wmiproperties) {

        if ($package.IdentifyingNumber -eq $property.ProductCode) {
           [void]$packageinfo.Rows.Add($package.Name,$package.IdentifyingNumber, $property.Value)
           $foundupgradecode = $true
           break
        }
    }

    if(-Not ($foundupgradecode)) { 
         # No upgrade code found, add product code to list
         [void]$packageinfo.Rows.Add($package.Name,$package.IdentifyingNumber, "") 
    }

}

$packageinfo | Format-table ProductCode, UpgradeCode, Name

# Enable the following line to export to CSV (good for annotation). Set full path in quotes
# $packageinfo | Export-Csv "[YourFullWriteablePath]\MsiInfo.csv"

# copy this line as well

在远程计算机上运行

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆