.net 在不使用 msiexec 的情况下从命令行卸载 MSI 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/450027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 11:00:55  来源:igfitidea点击:

Uninstalling an MSI file from the command line without using msiexec

.netcommand-lineinstallationwindows-installermsiexec

提问by xarzu

msiexecis command prompt software that installs an MSIprogram. But I have found that you can install an MSI file from the command line by just typing in the name of the MSI file on the command line.

msiexec是安装MSI程序的命令提示符软件。但是我发现您只需在命令行中输入 MSI 文件的名称即可从命令行安装 MSI 文件。

But in order to uninstall the MSI file, it seems you have to call the msiexecprogram and give it a /xor /uninstall.

但是为了卸载 MSI 文件,您似乎必须调用该msiexec程序并给它一个/x/uninstall

How can I uninstall an MSI from the command line without using the msiexecroutine?

如何在不使用msiexec例程的情况下从命令行卸载 MSI ?

采纳答案by Roger Lipscombe

Short answer: you can't. Use MSIEXEC /x

简短的回答:你不能。使用 MSIEXEC /x

Long answer: When you run the MSI file directly at the command line, all that's happening is that it runs MSIEXEC for you. This association is stored in the registry. You can see a list of associations by (in Windows Explorer) going to Tools / Folder Options / File Types.

长答案:当您直接在命令行中运行 MSI 文件时,所发生的一切就是它为您运行 MSIEXEC。此关联存储在注册表中。您可以通过(在 Windows 资源管理器中)转到工具/文件夹选项/文件类型来查看关联列表。

For example, you can run a .DOC file from the command line, and WordPad or WinWord will open it for you.

例如,您可以从命令行运行 .DOC 文件,写字板或 WinWord 将为您打开它。

If you look in the registry under HKEY_CLASSES_ROOT\.msi, you'll see that .MSI files are associated with the ProgID "Msi.Package". If you look in HKEY_CLASSES_ROOT\Msi.Package\shell\Open\command, you'll see the command line that Windows actually uses when you "run" a .MSI file.

如果您查看 下的注册表HKEY_CLASSES_ROOT\.msi,您将看到 .MSI 文件与 ProgID“Msi.Package”相关联。如果查看HKEY_CLASSES_ROOT\Msi.Package\shell\Open\command.MSI 文件,则会看到 Windows 实际使用的命令行。

回答by Stein ?smul

There are many ways to uninstall an MSI package. This is intended as a "reference".

卸载 MSI 包的方法有很多种。这旨在作为“参考”。

In summaryyou can uninstall via: msiexec.exe, ARP, WMI, PowerShell, Deployment Systems such as SCCM, VBScript/ COM Automation, DTF, or via hidden Windows cache folder, and a few other options presented below.

总之,您可以通过以下方式卸载:msiexec.exeARPWMIPowerShell、部署系统(例如SCCMVBScript/COM 自动化、DTF)或通过隐藏的 Windows 缓存文件夹以及下面介绍的一些其他选项。

The first few paragraphs provide important MSI tidbits, then there are 14 sectionswith different ways to uninstall an MSI file. Puh.

前几段提供了重要的 MSI 花絮,然后有14 个部分提供了不同的卸载 MSI 文件的方法。噗。

"Babble, Babble - Over":Sections 1, 2and 3are the normal uninstall approaches(and hence recommended). Personally I use option 3 or 5 from section 3(both options with logging, but option 5 runs silently as well). If you are very busy, skip all the babble and go for one of these - it will get the job done.

“潺潺,串音-过”:123正常卸载接近(因此推荐)。Personally I use option 3 or 5 from section 3(两个选项都带有日志记录,但选项 5 也会静默运行)。如果你很忙,跳过所有的胡言乱语,选择其中一个——它会完成工作。



If you have problems uninstalling altogetherand are looking for an alternative to the deprecated MsiZap.exeand / or Windows Installer CleanUp Utility (MSICUU2.exe), you can try the new FixIt tool from Microsoft(or the international page). May apparently work for other install issues as well.

如果您在完全卸载时遇到问题并且正在寻找已弃用的替代方案微信小程序和/或 Windows Installer 清理实用程序(MSICUU2.exe),您可以尝试Microsoft的新FixIt 工具或国际页面)。显然也适用于其他安装问题。

Newer list of cleanup approaches: Cleaning out broken MSI uninstalls.

更新的清理方法列表:清理损坏的 MSI 卸载.



If you think MSIand Windows Installeris more trouble than it's worth, you might want to read about the corporate benefits of using MSI files.

如果您认为MSIWindows Installer比它的价值更麻烦,您可能需要阅读有关使用 MSI 文件的公司优势的信息



Installscript MSIsetups generally come wrapped in a setup.exe file. To read more about the parameters to use for uninstalling such setups please see these links: setup.exe pdf reference sheet, Setup.exe and Update.exe Command-Line Parameters.

Installscript MSI设置通常包含在setup.exe 文件中。要了解有关用于卸载此类设置的参数的更多信息,请参阅以下链接:setup.exe pdf 参考表Setup.exe 和 Update.exe 命令行参数



Some MSI files are installed as part of bundlesvia mechanism such as Burn(WiX Toolkit) or InstallShield Suiteprojects. This can make uninstall slightly different from what is seen below. Here is an example for InstallShield Suite projects.

某些 MSI 文件通过Burn(WiX Toolkit) 或InstallShield Suite项目等机制作为包的一部分安装。这可以使卸载与下面看到的略有不同。以下是InstallShield Suite 项目的示例



Be aware that running uninstall silentlyor interactivelycan cause different results (!). For a rather lengthy description of why this is the case, please read this post: Uninstall from Control Panel is different from Remove from .msi

请注意,以静默方式交互方式运行卸载可能会导致不同的结果 (!)。有关为什么会出现这种情况的详细说明,请阅读这篇文章:从控制面板卸载不同于从 .msi 删除



If you are unexpectedly asked for the original installation media when trying to uninstall, please read this answer: Why does MSI require the original .msi file to proceed with an uninstall?and perhaps also section 12 below for some important technical details.

如果在尝试卸载时意外要求您提供原始安装介质,请阅读此答案:为什么 MSI 需要原始 .msi 文件才能继续卸载?也许还有下面的第 12 节,了解一些重要的技术细节。



If you got CCleaneror similar cleanup tools installed, perhaps jump to section 11.

如果您安装了CCleaner或类似的清理工具,请跳到第 11 节



If uninstall is failing entirely (not possible to run), see sections 12 & 13 belowfor a potential way to "undo" the installation using system restoreand / or cleanup tools.

如果卸载完全失败(无法运行),请参阅下面的第 12 和 13 节,了解使用系统还原和/或清理工具“撤消”安装的潜在方法。



1. Using the original MSI

1. Using the original MSI

  • If you have access to the original MSI used for the installation, you can simply right clickit in Windows Explorerand select Uninstall.
  • You can also uninstall via command line as explained in section 3.
  • 如果您有权访问用于安装的原始 MSI,您只需在Windows 资源管理器中右键单击它并选择卸载
  • 您还可以通过命令行卸载,如第 3 节所述。


2. Using the old ARP Applet OR new Windows 8/10 Settings Interface

2. Using the old ARP Applet OR new Windows 8/10 Settings Interface

  • Just got to mention the normal approach(es) though it is obvious

    • ARP= Add / Remove Programs Applet(appwiz.cpl)
    • Windows 10 Settings Interface=> New shell for same operation
  • ARP:

    • Go startrunappwiz.cplENTERin order to open the add/remove programs applet (or click add/ remove programs in the control panel)
    • Click "Remove" for the product you want to uninstall
  • Settings Interface(Windows 8 / 10):

    • Use the new Settings GUI in Windows 8 / 10
    • Windows Key+ Tap I=> Apps & Features. Select entry and uninstall.
    • Some reports of errors when invoking uninstall this way. Please add comments below if seen.
  • 只是不得不提到正常的方法(ES)虽然很明显

    • ARP= Add / Remove Programs Applet( appwiz.cpl)
    • Windows 10 Settings Interface=> 相同操作的新外壳
  • ARP:

    • 转到开始运行APPWIZ.CPLENTER为了打开添加/删除程序(或单击控制面板中的添加/删除程序)
    • 对要卸载的产品点击“删除
  • 设置界面(Windows 8 / 10):

    • 在 Windows 8 / 10 中使用新的设置 GUI
    • Windows Key+ 点击I=> Apps & Features。选择进入并卸载。
    • 以这种方式调用卸载时的一些错误报告。如果看到请在下面添加评论。


3. Using msiexec.exe command line (directly or via a batch file)

3. Using msiexec.exe command line (directly or via a batch file)

  • You can uninstall via the command prompt(cmd.exe), batch fileor or even from within an executable as a shell operation.
  • You do this by passing the product GUID(check below for how to find this GUID) or the path to the original MSI file, if available, to msiexec.exe.
  • For all the command lines below you can add /qnto make the uninstall run in silent mode. This is how an uninstall runs when triggered from the add/remove applet.

    • Option 1: Basic interactive uninstall(access to original MSI file):

       msiexec.exe /x "c:\filename.msi"
      
    • Option 2: Basic interactive uninstall via product GUID(no access to original MSI file - here is how to find the product GUID- same link as below):

       msiexec.exe /x {11111111-1111-1111-1111-11111111111X}
      
    • Option 3: Interactive uninstall with verbose log file:

       msiexec.exe /x "c:\filename.msi" /L*V "C:\msilog.log"
       msiexec.exe /x {11111111-1111-1111-1111-11111111111X} /L*V "C:\msilog.log"
      
    • Option 4: Interactive uninstall with flushed, verbose log file(verbose, flush to log option- write log continuously, can be very slow):

       msiexec.exe /x "c:\filename.msi" /L*V! "C:\msilog.log"
       msiexec.exe /x {11111111-1111-1111-1111-11111111111X} /L*V! "C:\msilog.log"
      
      • The flush to log option makes the uninstall slowbecause the log file is written continuously instead of in batches. This ensures no log-buffer is lost if the setup crashes.

      • In other words, enable this option if your setup is crashing and there is no helpful information in your verbose log file. Remove the exclamation mark to turn off the flush to log option and the uninstall will be much quicker. You still get verbose logging, but as stated some log buffer could be lost.

    • Option 5 (recommended): Silent uninstall with verbose log file - suppress reboots(no flush to log - see previous option for what this means):

       msiexec.exe /x "c:\filename.msi" /QN /L*V "C:\msilog.log" REBOOT=R
       msiexec.exe /x {11111111-1111-1111-1111-11111111111X} /QN /L*V "C:\msilog.log" REBOOT=R
      

      Quick Parameter Explanation (since I recommend this option):

       /X = run uninstall sequence
       /QN = run completely silently
       /L*V "C:\msilog.log"= verbose logging at path specified
       {11111111-1111-1111-1111-11111111111X} = product guid of app to uninstall
       REBOOT=R = prevent unexpected reboot of computer
      

      Again, how to find the product guid: How can I find the product GUID of an installed MSI setup?(for uninstall if you don't have the original MSI to specify in the uninstall command).

  • Top tip: If you create a log file for your uninstall, you can locate problems in the log by searching for "value 3". This is particularly useful for verbose files, because they are so, well, verbose :-).

  • How to find the product GUID for an installed MSI?

  • More information on logging from installsite.org: How do I create a log file of my installation?- great overview of different options and also specifics of InstallShield logging.

  • Msiexec (command-line options)- overview of the command line for msiexec.exefrom MSDN. Here is the Technet version.
  • 您可以通过命令提示符( cmd.exe)、批处理文件或什至从可执行文件中作为shell 操作卸载。
  • 您可以通过将产品 GUID(检查下面如何查找此GUID)或原始 MSI 文件的路径(如果可用)传递给msiexec.exe 来完成此操作
  • 对于下面的所有命令行,您可以添加/qn使卸载以静默模式运行。这是从添加/删除小程序触发时卸载的运行方式。

    • 选项 1:基本交互式卸载(访问原始 MSI 文件):

       msiexec.exe /x "c:\filename.msi"
      
    • 选项 2:通过产品 GUID 进行基本交互式卸载(无法访问原始 MSI 文件 - 以下是查找产品 GUID 的方法- 与以下链接相同):

       msiexec.exe /x {11111111-1111-1111-1111-11111111111X}
      
    • 选项 3:使用详细日志文件进行交互式卸载

       msiexec.exe /x "c:\filename.msi" /L*V "C:\msilog.log"
       msiexec.exe /x {11111111-1111-1111-1111-11111111111X} /L*V "C:\msilog.log"
      
    • 选项 4:使用刷新的详细日志文件进行交互式卸载详细、刷新到日志选项- 连续写入日志,可能会很慢):

       msiexec.exe /x "c:\filename.msi" /L*V! "C:\msilog.log"
       msiexec.exe /x {11111111-1111-1111-1111-11111111111X} /L*V! "C:\msilog.log"
      
      • 刷新到日志选项会使卸载速度变慢,因为日志文件是连续写入的,而不是分批写入的。这可确保在设置崩溃时不会丢失日志缓冲区。

      • 换句话说,如果您的设置崩溃并且详细日志文件中没有有用的信息,请启用此选项。删除感叹号以关闭刷新到日志选项,卸载会更快。您仍然会得到详细的日志记录,但如前所述,一些日志缓冲区可能会丢失。

    • 选项 5(推荐):使用详细日志文件静默卸载 - 禁止重新启动(不刷新到日志 - 请参阅上一个选项以了解其含义):

       msiexec.exe /x "c:\filename.msi" /QN /L*V "C:\msilog.log" REBOOT=R
       msiexec.exe /x {11111111-1111-1111-1111-11111111111X} /QN /L*V "C:\msilog.log" REBOOT=R
      

      快速参数说明(因为我推荐这个选项):

       /X = run uninstall sequence
       /QN = run completely silently
       /L*V "C:\msilog.log"= verbose logging at path specified
       {11111111-1111-1111-1111-11111111111X} = product guid of app to uninstall
       REBOOT=R = prevent unexpected reboot of computer
      

      同样,如何找到产品 guid: 如何找到已安装 MSI 设置的产品 G​​UID?(用于卸载,如果您没有在卸载命令中指定的原始 MSI)。

  • 重要提示:如果您为卸载创建日志文件,则可以通过搜索“值 3”来查找日志中的问题。这对于冗长的文件特别有用,因为它们是如此,好,冗长:-)。

  • 如何查找已安装 MSI 的产品 G​​UID

  • 有关从installsite.org登录的更多信息:如何创建安装的日志文件- 对不同选项以及 InstallShield 日志记录细节的全面概述。

  • MSIEXEC(命令行选项)-为对命令行的概述MSIEXEC.EXEMSDN。这是Technet 版本


4. Using the cached MSI database in the super hidden cache folder

4. Using the cached MSI database in the super hidden cache folder

  • MSI strips out all cabs (older Windows versions) and caches each MSI installed in a super-hidden system folder at %SystemRoot%\Installer(you need to show hidden files to see it).
  • NB: This supper-hidden folder is now being treated differently in Windows 7 onwards. MSI files are now cached full-size. Read the linked thread for more details - recommended read for anyone who finds this answer and fiddles with dangerous Windows settings.
  • All the MSI files here will have a random name (hex format) assigned, but you can get information about each MSI by showing the Windows Explorer status bar (View -> Status Bar) and then selecting an MSI. The summary stream from the MSI will be visible at the bottom of the Windows Explorer window. Or as Christopher Galpin points out, turn on the "Comments" column in Windows Explorer and select the MSI file (see this article for how to do this).
  • Once you find the right MSI, just right click it and go Uninstall.
  • You can also use PowerShell to show the full path to the locally cached package along with the product name. This is the easiest option in my opinion.
  • To fire up PowerShell: hold down the Windows key, tap R, release the Windows key, type in "powershell" and press OK. Then maximize the PowerShell windowand run the command below:
  • MSI 去除所有 cab(较旧的 Windows 版本)并将安装在%SystemRoot%\Installer的超级隐藏系统文件夹中的每个 MSI 缓存(您需要显示隐藏文件才能看到它)。
  • 注意:这个超级隐藏的文件夹现在在 Windows 7 中被区别对待。MSI 文件现在缓存为全尺寸. 阅读链接的线程以获取更多详细信息 - 推荐阅读此答案并摆弄危险 Windows 设置的任何人。
  • 此处的所有 MSI 文件都将分配一个随机名称(十六进制格式),但您可以通过显示 Windows 资源管理器状态栏(查看 -> 状态栏)然后选择 MSI 来获取有关每个 MSI 的信息。来自 MSI 的摘要流将显示在 Windows 资源管理器窗口的底部。或者正如 Christopher Galpin 指出的那样,打开 Windows 资源管理器中的“评论”列并选择 MSI 文件(有关如何执行此操作,请参阅本文)。
  • 找到正确的 MSI 后,只需右键单击它并进行卸载。
  • 您还可以使用 PowerShell 显示本地缓存包的完整路径以及产品名称。这是我认为最简单的选择。
  • 要启动PowerShell按住 Windows 键,点击 R,松开 Windows 键,输入“powershell”并按 OK。然后最大化 PowerShell 窗口并运行以下命令:
    get-wmiobject Win32_Product | Format-Table Name, LocalPackage -AutoSize

Enter image description here

在此处输入图片说明



5. UsingPowerShell

5. UsingPowerShell

  • MSDN 上一个类似但更全面的 PowerShell 脚本。它允许在多台机器上运行卸载。
  • Even Mien 添加的条目:

    $app = Get-WmiObject -Class Win32_Product -Filter "Name = 'YOUR_APP'"
    $app.Uninstall()
    
  • 这种方法是可行的,但是访问 WMI 类 Win32_Product 会触发软件一致性检查,该检查非常慢,并且在特殊情况下可能会导致触发 MSI 自我修复。请参阅这篇文章:Powershell 卸载脚本 - 真的很头疼

  • 我自己没有测试过这个,但看起来 $app.Uninstall() 可能会运行在 ARP 小程序的注册表设置中注册的 UninstallString。这意味着在某些情况下它可能会运行修改而不是卸载。
  • 查看此主题以获取更多详细信息和通过 Powershell 卸载的方法:如何使用 PowerShell 卸载应用程序?


6. Using the .NET DTF Class Library(part of the WiX toolkit)

6. Using the .NET DTF Class LibraryWiX 工具包的一部分)

    using Microsoft.Deployment.WindowsInstaller;

    public static void Uninstall( string productCode)
    {
      Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\"");
    }


7. Using theWindows Installer Automation API

7. Using theWindows Installer Automation API



8. Using aWindows Installer major upgrade

8. Using aWindows Installer major upgrade

  • A Windows Installer major upgrade may happen as part of the installation of another MSI file.
  • A major upgrade is authored by identifying related products in the MSI's "Upgrade table". These related setups are then handled as specified in the table. Generally that means they are uninstalled, but the main setup can also be aborted instead (typically used to detect higher versions of your own application present on the box).
  • Windows Installer 主要升级可能会作为安装另一个 MSI 文件的一部分发生。
  • 通过在 MSI 的“升级表”中识别相关产品来进行重大升级。然后按照表中的规定处理这些相关的设置。通常这意味着它们已被卸载,但也可以中止主设置(通常用于检测盒子上存在的您自己的应用程序的更高版本)。


9. Using Deployment Systems / Remote Administration Systems

9. Using Deployment Systems / Remote Administration Systems

  • SCCM, CA Unicenter, IBM's Tivoli, AltirisClient Management Suite, and several others
  • These tools feature advanced client PC management, and this includes the install and uninstall of MSI files
  • These tools seem to use a combination of msiexec.exe, automation, WMI, etc... and even their own way of invoking installs and uninstalls.
  • In my experience these tools feature a lot of "personality" and you need to adapt to their different ways of doing things.
  • SCCMCA UnicenterIBM 的 TivoliAltirisClient Management Suite 和其他几个
  • 这些工具具有高级客户端 PC 管理功能,包括安装和卸载 MSI 文件
  • 这些工具似乎结合了 msiexec.exe、自动化、WMI等......甚至它们自己的调用安装和卸载的方式。
  • 根据我的经验,这些工具具有很多“个性”,您需要适应它们不同的做事方式。


10. Using WMI - Windows Management Instrumentation

10. Using WMI - Windows Management Instrumentation



11. Using a third-party tool such asccleaneror similar

11. Using a third-party tool such asccleaneror similar

  • Several Windows applications feature their own interface for uninstalling not just MSI packages, but legacy installers too.
  • I don't want to make any specific tool recommendations here (especially commercial ones), but the well known CCleanerfeatures such an uninstall interface (and it has a free version). I should also add that this tool suffered a malware attack recently.
  • I guess we should all remember that even harmless software can be injected with malware in their download locations (FTP attack).
    • I use virustotal.comto check my downloads, and also Sysinternals Process Explorerto check running processes after installation - along with regular security software (whichever is available).
    • A surprising amount of "gray area" software is usually found with this approach (toolbars, smileys, adware, etc...), along with several false positives (they can also cause problems as security software block their access or quarantines them making a lot of fuzz). And certainly real malware as well.
    • Some usage tips for Process Explorer can be found here- a series of tweets - this Process Explorer tool hooks up to VirusTotal.comto check all running processes interactively - all you need is a few configuration steps.
    • I should note that Process Explorer yields a file signature check, but no heuristics - as far as I understand (no check for suspicious operations, just a check with 60+ security suites for flagged files). You need a regular security tool for interactive, online heuristic protection.
    • For what it is worth, I think some security software border on causing more false-positive problems than malware does damage. Famous last words in the era of ransom-ware...
    • That is a large enough digression - I just don't want to see people download malware. Do your virustotal.comcheck at least.
  • Uninstalling like this should work OK. I think these tools mess with too many things when you try their "cleanup features" though. Use with caution. If you only use the uninstall feature, you should be OK.
  • 一些 Windows 应用程序具有自己的界面,不仅可以卸载 MSI 软件包,还可以卸载旧版安装程序。
  • 我不想在这里提出任何具体的工具推荐(尤其是商业工具),但众所周知的CCleaner具有这样的卸载界面(并且它有一个免费版本)。我还应该补充一点,该工具最近遭受了恶意软件攻击
  • 我想我们都应该记住,即使是无害的软件也可以在其下载位置注入恶意软件(FTP 攻击)。
    • 我使用virustotal.com来检查我的下载,并使用Sysinternals Process Explorer来检查安装后正在运行的进程——以及常规安全软件(以可用者为准)。
    • 使用这种方法通常会发现数量惊人的“灰色地带”软件(工具栏、表情符号、广告软件等),以及一些误报(它们也可能导致问题,因为安全软件会阻止他们的访问或隔离他们很多绒毛)。当然也是真正的恶意软件。
    • 可以在此处找到 Process Explorer 的一些使用技巧- 一系列推文 - 此 Process Explorer 工具连接到VirusTotal.com以交互方式检查所有正在运行的进程 - 您只需要几个配置步骤。
    • 我应该注意到 Process Explorer 产生了文件签名检查,但没有启发式 - 据我所知(没有检查可疑操作,只是检查 60 多个安全套件的标记文件)。您需要一个常规的安全工具来进行交互式在线启发式保护。
    • 就其价值而言,我认为某些安全软件可能会导致误报问题多于恶意软件造成的损害。勒索软件时代的著名遗言...
    • 这是一个足够大的题外话 - 我只是不想看到人们下载恶意软件。至少检查您的virustotal.com
  • 像这样卸载应该可以正常工作。不过,我认为当您尝试使用它们的“清理功能”时,这些工具会弄乱太多东西。谨慎使用。如果你只使用卸载功能,你应该没问题。


12. Using a cleanup tool such asmsizapor similar

12. Using a cleanup tool such asmsizapor similar

  • For completeness msizap.exeshould be mentioned though it is deprecated, unsupportedand outdated. It should not be used on any newer Windows versions
  • This command line tool (msizap.exe) also had a GUI available (MSICUU2.exe). Both tools are deprectated.
  • The intended use of these tools was to clean out failing uninstalls:
  • Generally for the rare case when the cached MSI with the random name is erroneously missingand uninstall fails for this reason whilst asking for the original MSI. This is a rare problem, but I have seen it myself. Just a few potential causes: Moved to this answer.
    • Key words: system restore interference, bad cleanup apps, msiexec.exe crashing, power outage, security software interference, MSI development debugging blunders (identical package codes, etc...), user tinkering and hacking (what is in here? save space?), etc...
    • It could also be used to zap any MSI installation, though that is obviously not advisable.
    • More information: Why does MSI require the original .msi file to proceed with an uninstall?
  • This newer support tool(this tool is now also deprecated) can be tried on recent Windows versions if you have defunct MSI packages needing uninstall.
  • Some have suggested to use the tool linked to here by saschabeaumont: Uninstall without an MSI file. If you try it and it works, please be sure to let us know.
  • If you have access to the original MSI that was actually used to install the product, you can use this to run the uninstall. It must be the exact MSI that was used, and not just a similar one.
  • 为了完整性 msizap.exe应该提到,尽管它已被弃用不受支持过时。它不应用于任何较新的 Windows 版本
  • 这个命令行工具(msizap.exe) 还有一个可用的 GUI (MSICUU2.exe)。这两个工具都已弃用。
  • 这些工具的预期用途是清除失败的卸载
  • 通常情况下,当具有随机名称的缓存 MSI 错误丢失并且卸载失败时,同时要求原始 MSI 的情况很少见。这是一个罕见的问题,但我自己也见过。只是一些潜在的原因:移到这个答案
    • 关键词:系统还原干扰、不良清理应用程序、msiexec.exe 崩溃、断电、安全软件干扰、MSI 开发调试错误(相同的包代码等...)、用户修补和黑客攻击(这里有什么?节省空间) ?), 等等...
    • 它也可以用于清除任何 MSI 安装,尽管这显然是不可取的。
    • 更多信息:为什么 MSI 需要原始 .msi 文件才能继续卸载?
  • 这个较新的支持工具(此工具现在也已弃用)如果您有需要卸载的已失效 MSI 软件包,可以在最近的 Windows 版本上试用。
  • 有些人建议使用 saschabeaumont 链接到的工具:卸载没有 MSI 文件。如果您尝试并有效,请务必告诉我们。
  • 如果您有权访问实际用于安装产品的原始 MSI,则可以使用它来运行卸载。它必须是所使用的确切 MSI,而不仅仅是类似的 MSI。


13. Usingsystem restore("installation undo" - last resort IMHO)

13. Usingsystem restore("installation undo" - last resort IMHO)

  • This is strictly speaking not a way to "uninstall" but to "undo" the last install, or several installs for that matter.
  • Restoring via a restore point brings the system back to a previous installation state(you can find video demos of this on YouTube or a similar site).
  • Note that the feature can be disabled entirely or partly - it is possible to disable permanently for the whole machine, or adhoc per install.
  • I have seen new, unsolvable installation problems resulting from a system restore, but normally it works OK. Obviously don't use the feature for fun. It's a last resort and is best used for rollback of new driversor setups that have just been installed and are found to cause immediate problems (bluescreen, reboots, instability, etc...).
  • The longer you go back the more rework you will create for yourself, and the higher the risk will be. Most systems feature only a few restore points, and most of them stretch back just a month or two I believe.
  • Be aware that system restore might affect Windows Updatesthat must then be re-applied - as well as many other system settings. Beyond pure annoyances, this can also cause security issues to resurface and you might want to run a specific security check on the target box(es) using Microsoft Baseline Security Analyzeror similar tools.
  • Since I mentioned system restore I suppose I should mention the Last Known Good Configuration feature. This feature has nothing to do with uninstall or system restore, but it is the last boot configuration that worked or resulted in a running system. It can be used to get your system running again if it bluescreens or halts during booting. This often happens after driver installs.
  • 严格来说,这不是“卸载”而是“撤消”最后一次安装或多次安装的方法。
  • 通过还原点进行还原会将系统恢复到之前的安装状态(您可以在 YouTube 或类似网站上找到相关视频演示)。
  • 请注意,该功能可以完全或部分禁用 - 可以永久禁用整个机器,或者每次安装时临时禁用。
  • 我见过系统还原导致的新的、无法解决的安装问题,但通常它可以正常工作。显然不要为了好玩而使用该功能。这是最后的手段,最适合用于回滚刚刚安装的新驱动程序或设置,并发现会立即导致问题(蓝屏、重新启动、不稳定等)。
  • 你回去的时间越长,你为自己创造的返工就越多,风险就越大。大多数系统只有几个还原点,我相信它们中的大多数都可以追溯到一两个月。
  • 请注意,系统还原可能会影响必须重新应用的Windows 更新以及许多其他系统设置。除了纯粹的烦恼之外,这还可能导致安全问题再次出现,您可能希望使用Microsoft 基线安全分析器或类似工具对目标框运行特定的安全检查。
  • 既然我提到了系统还原,我想我应该提到最后一次正确的配置功能。此功能与卸载或系统还原无关,但它是上次运行或导致系统运行的引导配置。如果系统在启动过程中出现蓝屏或停止,它可用于让您的系统再次运行。这通常发生在驱动程序安装后。


14. Windows Installer Functions (C++)

14. Windows Installer Functions (C++)

For completeness I guess we should mention the core of it all - the down-to-the-metal way: the Win32 Windows Installer API functions. These are likely the functions used by most, if not all of the other approaches listed above "under the hood". They are primarily used by applications or solutions dealing directly with MSI as a technology.

为了完整起见,我想我们应该提到这一切的核心 - 实事求是的方式:Win32 Windows Installer API 函数。这些可能是大多数(如果不是所有)上面“幕后”列出的其他方法使用的功能。它们主要由直接将 MSI 作为技术处理的应用程序或解决方案使用。

There is an answer on serverfault.com which may be of interest as a summary of the different programmatic approaches for uninstalling(COM Automation, .NET, Win32 installer functions).

serverfault.com 上有一个答案,作为卸载(COM 自动化、.NET、Win32 安装程序功能)的不同编程方法的摘要,您可能会对此感兴趣。

Below you will find a C++ snippet showing how to uninstall Orca, 10.1.17134.12by product code using a call to the MsiConfigureProductEx function. To uninstall another product replace the GUID specified for prodcodewith the one for your product. To find the product code see this answer: How can I find the product GUID of an installed MSI setup?

您将在下面找到一个 C++ 代码段,显示如何Orca, 10.1.17134.12使用对MsiConfigureProductEx 函数的调用按产品代码卸载。要卸载另一个产品,请将为其指定的 GUID 替换prodcode为您的产品的 GUID 。要查找产品代码,请参阅此答案:如何找到已安装 MSI 设置的产品 G​​UID?

The uninstall will happen in full GUI mode. To run in silent mode or some other GUI mode (reduced, basic, etc...), please see the: MsiSetInternalUI function.

卸载将在完整的 GUI 模式下进行。要以静默模式或其他一些 GUI 模式(简化、基本等...)运行,请参阅:MsiSetInternalUI 函数

#include "pch.h"

#define WIN32_LEAN_AND_MEAN //Minimize includes from Windows.h
#include <windows.h>
#include <msi.h> // Windows Installer
#include <tchar.h> 

#pragma comment(lib, "msi.lib") // To make code link

int main()
{
    const TCHAR noreboot[] = _T("REBOOT=ReallySuppress");
    const TCHAR prodcode[39] = _T("{D7B80ABC-1950-37B8-F851-C3783EED9C93}"); // Orca, 10.1.17134.12

    UINT res = MsiConfigureProductEx(prodcode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_ABSENT, noreboot);

    return res; // Error Codes: https://msdn.microsoft.com/en-us/library/windows/desktop/aa376931(v=vs.85).aspx
}

The snippet was made and tested with the latest version of Visual Studio 2017as of September 2018:

该代码段是在2018 年 9 月使用最新版本的Visual Studio 2017制作和测试的:

  1. Create a new "Windows Console Application" from Visual C++ => Windows Desktop.
  2. Copy and paste the above code into your main CPP file (replacing whatever is there).
  3. That should be it to be able to run the code. Maybe set a breakpoint, build and run.

  1. 从 Visual C++ => Windows 桌面创建一个新的“Windows 控制台应用程序”。
  2. 将上面的代码复制并粘贴到您的主 CPP 文件中(替换那里的任何内容)。
  3. 那应该是能够运行代码。也许设置一个断点,构建并运行。

    • 注意 VS2017 中对默认模板的更改,以及可能导致的奇怪错误:IntelliSense 引擎无法正常运行的错误太多
    • 2018 年 9 月更新:模板再次更改。我不再看到上述问题。
    • 代码中的 MSDN 链接列出了从 msiexec.exe 返回的可能错误消息。

回答by themrnutz

Also remember that an uninstall can be initiated using the WMIC command:

还请记住,可以使用 WMIC 命令启动卸载:

wmic product get name--> This will list the names of all installed apps

wmic product get name--> 这将列出所有已安装应用程序的名称

wmic product where name='myappsname' call uninstall--> this will uninstall the app.

wmic product where name='myappsname' call uninstall--> 这将卸载应用程序。

回答by Tuminoid

The msifile extension is mapped to msiexec (same way typing a .txt filename on a command prompt launches Notepad/default .txtfile handler to display the file).

msi文件的扩展名被映射到MSIEXEC(同样的方式输入的命令为.txt文件名提示启动记事本/默认.txt文件处理程序,以显示文件)。

Thus typing in a filename with an .msi extension really runs msiexec with the MSI file as argument and takes the default action, install. For that reason, uninstalling requires you to invoke msiexec with uninstall switch to unstall it.

因此,输入带有 .msi 扩展名的文件名实际上会以 MSI 文件作为参数运行 msiexec 并采用默认操作安装。因此,卸载需要您使用卸载开关调用 msiexec 来卸载它。

回答by sdaffa23fdsf

wmic product get name

Just gets the cmd stuck... still flashing _ after a couple minutes

只是让 cmd 卡住了......几分钟后仍然闪烁 _

in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, if you can find the folder with the software name you are trying to install (not the one named with ProductCode), the UninstallString points to the application's own uninstaller C:\Program Files\Zune\ZuneSetup.exe /x

在 中HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,如果您可以找到具有您尝试安装的软件名称的文件夹(不是以 ProductCode 命名的文件夹),则 UninstallString 指向应用程序自己的卸载程序C:\Program Files\Zune\ZuneSetup.exe /x

回答by sdaffa23fdsf

I would try the following syntax - it works for me.

我会尝试以下语法 - 它对我有用。

msiexec /x filename.msi /q 

回答by smack0007

I'm assuming that when you type int file.msi into the command line, Windows is automatically calling msiexec file.msi for you. I'm assuming this because when you type in picture.png it brings up the default picture viewer.

我假设当您在命令行中键入 int file.msi 时,Windows 会自动为您调用 msiexec file.msi。我这样假设是因为当你输入 picture.png 时,它会显示默认的图片查看器。