使用 msiexec 卸载应用程序时,是否有替代 GUID 的方法? [英] Is there an alternative to GUID when using msiexec to uninstall an application?

查看:31
本文介绍了使用 msiexec 卸载应用程序时,是否有替代 GUID 的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前在运行包含 msiexec 的卸载脚本时使用 GUID 来识别应用程序.我遇到的问题是每次安装最新版本的应用程序时 GUID 都会更改,所以我想知道是否有不同的方法可以识别使用 msiexec 运行的应用程序?

We're currently using a GUID to identify the application when running our uninstall script which contains msiexec. The problem I'm having is the GUID changes every time I install the latest version of the application, so I was wondering if there is a different way that I can identify our application running using msiexec?

推荐答案

首先:新版本的应用程序的产品GUID变化是正常的,虽然也可以升级某些应用程序无需更改产品 GUID(称为 小升级 - 与主要升级 更改了产品 GUID).在同一产品的不同版本之间趋向于保持稳定的是 UpgradeCode(它定义了一系列相关产品).ProductCode 唯一标识产品(在特定版本中).

First of all: it is normal that the product GUID changes for new versions of the application, though it is also possible to upgrade some applications without changing the product GUID (referred to as minor upgrades - as opposed to major upgrades that change the product GUID). What tends to remain stable between different releases of the same product is the UpgradeCode (it defines a family of related products). ProductCode uniquely identifies a product (in a specific version).

此处列出了一些卸载选项:不使用 msiexec 从命令行卸载 MSI 文件.

There are some options for uninstall listed here: Uninstalling an MSI file from the command line without using msiexec.

我想您可以使用 section 3 中所示的 MSI 文件名,或者如果产品名称保持稳定,您可以将其与自动化一起使用以查找正确的产品 G​​UID 以卸载产品有问题.我稍后会对此进行测试并更新答案.

I suppose you could use the MSI file name as illustrated in section 3, or if the product name remains stable you could use it along with automation to look up the correct product GUID to uninstall the product in question. I will test this in a moment and update the answer.

更新:通过产品名称"卸载产品的示例 VBScript(假设它在不同版本之间保持不变,通常会这样做,但不能保证 - 这取决于产品).

UPDATE: A sample VBScript to uninstall product by "product name" (assuming it remains constant across releases, which it normally does, but there is no guarantee - it depends on the product).

在添加/删除程序中找到产品名称 - 或使用链接到此答案底部的小 VBScript 导出包含所有已安装软件包信息的小文本文件.

Find the product name in Add/Remove Programs - or use the tiny VBScript linked to at the bottom of this answer to export a little text file with info for all installed packages.

' On Error Resume Next ' Used to suppress errors

Const msiUILevelNone = 2
Const msiUILevelFull = 5
Const msiInstallStateAbsent = 2

Set installer = CreateObject("WindowsInstaller.Installer")
Set products = installer.ProductsEx("", "", 7)
installer.UILevel = msiUILevelFull  ' Running with full GUI (if available in MSI)
' installer.UILevel = msiUILevelNone ' Will run uninstall silently, run script with admin rights

' Get the product name from the user
productname = InputBox("Please enter the product name for the MSI package you wish to uninstall:")
If productname = vbCancel Or Trim(productname) = "" Then
   WScript.Quit(0)
End If    

' Iterate over all MSI packages on the box
For Each product In products

   currentproduct = product.InstallProperty("ProductName")

   If LCase(currentproduct) = LCase(productname) Then

      installer.ConfigureProduct product.productcode, 0, 2 ' msiInstallStateAbsent
      MsgBox "Ran uninstall for: " & currentproduct
      Exit For ' End product iteration, assuming only one product needed uninstall

   End If 

Next

Set installer = Nothing

MsgBox "Finished."

<小时>

更新:您可以使用 VBScript 创建自己的产品代码和产品名称快速列表,如本答案底部所述:如何找到已安装的 MSI 设置的产品 G​​UID? .这个特殊的 VBScript 和我想的一样简单.


UPDATE: You can create yourself a quick list of product codes and product names using VBScript as described towards the bottom of this answer: How can I find the product GUID of an installed MSI setup? . This particular VBScript is as simple as it can possibly get I think.

这篇关于使用 msiexec 卸载应用程序时,是否有替代 GUID 的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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