当前位置:  开发笔记 > 编程语言 > 正文

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

如何解决《在不使用msiexec的情况下从命令行卸载MSI文件》经验,为你挑选了3个好方法。

msiexec是安装MSI程序的命令提示符软件.但我发现只需在命令行输入MSI文件的名称,就可以从命令行安装MSI文件.

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

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



1> Stein Åsmul..:

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

In summary you 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.

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

1,23正常卸载方法(因此推荐).我个人使用第3节中的选项3或5(两个选项都带有日志记录,但选项5也以静默方式运行).如果你很忙,可以跳过所有的唠叨,然后选择其中一个 - 它将完成工作.


如果您在完全卸载时遇到问题,并且正在寻找已弃用的替代方案MSIZAP.EXE 和/或Windows Installer CleanUp Utility(MSICUU2.exe),您可以尝试从Microsoft(或国际页面)的新FixIt工具.可能显然也适用于其他安装问题.


如果您认为MSIWindows Installer比它的价值更麻烦,您可能想了解使用MSI文件的公司优势.


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


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


请注意,以静默方式交互方式运行卸载会导致不同的结果(!).有关为什么会出现这种情况的相当冗长的描述,请阅读以下文章:从控制面板卸载与从.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.


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


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


1. Using the original MSI

如果您可以访问用于安装的原始MSI,则只需在Windows资源管理器中右键单击它,然后选择" 卸载".

您也可以通过命令行卸载,如第3节中所述.


2.使用ARP(添加/删除程序)小程序

只是提到了正常的方法虽然很明显

开始 ? 运行 ? APPWIZ.CPL ? ENTER以打开添加/删除程序(或单击添加/删除控制面板程序)

单击要删除的产品的" 删除 ".


3.使用msiexec.exe命令行(直接或通过批处理文件)

You can uninstall via the command prompt (cmd.exe), batch file or 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 Personally I use option 3 or 5 from section 3 to 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"

选项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"

flush to log选项使卸载变慢,因为日志文件是连续写入而不是批量写入.这可确保在安装程序崩溃时不会丢失日志缓冲区.

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?

There are several ways, my recommended way is using Powershell: How can I find the product GUID of an installed MSI setup?

Several other ways described here (registry, local cache folder, etc...): Find GUID From MSI File

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.exe from MSDN. Here is the Technet version.


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 window and run the command below:

    get-wmiobject Win32_Product | Format-Table Name, LocalPackage -AutoSize

Enter image description here

Also see this answer: How can I find the product GUID of an installed MSI setup?


5. Using PowerShell

There is a similar, but more comprehensive PowerShell script available on MSDN. It allows uninstall to be run on several machines.

Entry added by Even Mien:

$app = Get-WmiObject -Class Win32_Product -Filter "Name = 'YOUR_APP'"
$app.Uninstall()

This approach will work, but accessing the WMI class Win32_Product will trigger a software consistency check which is very slow and in special circumstances it can cause an MSI self-repair to be triggered. See this article: Powershell Uninstall Script - Have a real headache

I have not tested this myself, but it appears $app.Uninstall() may run the UninstallString registered in the ARP applet's registry settings. This means it may run modify instead of uninstall in some cases.

Check this topic for more details and ways to uninstall via Powershell: How can I uninstall an application using PowerShell?


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

This option is included for developers getting into deployment and MSI - it is not really practical as a "quick fix". It requires that you download the WiX toolkit - a free framework for creating MSI files compiled from XML source file(s).

A quick blurb on WiX and its "history": Windows Installer and the creation of WiX. And here is WiX contrasted with other deployment tools (commercial) - (strengths and weaknesses - hopefully as objective as possible).

DTF (Deployment Tools Foundation) is distributed as part of WiX as explained here: Is source-code for Deployment Tools Foundation available?.

DTF is essentially a .NET wrapper for the Win32 Windows Installer API. It eliminates all need for COM Interop when working with Windows Installer via automation and is nothing short of a .NET jewel - perhaps the easiest-to-use .NET library I have ever seen. Highly recommended - great even for training students in C#.

The following source from MSI expert Christopher Painter using C# and DTF. Microsoft.Deployment.WindowsInstaller is one of the DTF assemblies. See the other assemblies explained here on serverfault.com:

    using Microsoft.Deployment.WindowsInstaller;

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

Anther alternative from Tom Blodget: Checking for successful uninstall

More information on msiexec.exe versus automation on: serverfault.com.


7. Using the Windows Installer Automation API

Here is a community discussion of this option: Windows Installer Automation API community sample

The API can be accessed via script automation and C++ API calls (my post on serverfault.com)

The following source adapted from MSI expert Christopher Painter using VBScript:

Set installer = CreateObject("WindowsInstaller.Installer")
installer.InstallProduct "product.msi", "REMOVE=ALL REBOOT=ReallySuppress"
Set installer = Nothing

Here is another VBScript for uninstalling by GUID from Symantec: http://www.symantec.com/connect/downloads/uninstall-application-using-guid-registry

Uninstall via upgrade code & ConfigureProduct.


8. Using a Windows 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).


9. Using an advanced deployment system/Remote Administration System

SCCM, CA Unicenter, IBM's Tivoli, Altiris Client 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.


10. Using WMI - Windows Management Instrumentation

Adding just for completeness. It is not recommended to use this approach since it is very slow

A software consistency check is triggered every time Win32_Product is called of each installation

The consistency check is incredibly slow, and it may also trigger a software repair. See this article: Powershell Uninstall Script - Have a real headache

Even worse, some people report their event logs filling up with MsiInstaller EventID 1035 entries - apparently caused by WMI queries to the Win32_Product class (personally I have never seen this).

The WMICodeCreator.exe code creation tool can be used to experiment

Install can be invoked via Using the original MSI

Uninstall can be invoked via Using the old ARP Applet OR new Windows 8/10 Settings Interface

MSDN sample: Uninstall method of the Win32_Product class


11. Using a third-party tool such as ccleaner or 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 CCleaner


关于%SystemRoot%\ Installer,只需打开"注释"列即可.
不幸的是,*Windows Installer Automation Api*链接已经死亡,Google和WayBackMachine™没有缓存.你能用新的链接更新你的答案吗?谢谢!

2> Roger Lipsco..:

简短的回答:你做不到.使用MSIEXEC/x

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

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

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


实际上,您可以通过替换注册表中的命令来包含选项/ x.但我确定没有人愿意这样做,因为如果你这样做,你就不能再通过双击来安装msi.
不确定我同意[roger-lipscombe](http://stackoverflow.com/users/8446)的"你不能".在我的WinXP安装中,`HKEY_CLASSES_ROOT\Msi.Package\shell\Open\command`包含`"%SystemRoot%\ System32\msiexec.exe"/ i"%1"%*`.似乎是否愿意指定`/ i`安装在`cmd.exe`中,他们可以(默认情况下)指定MSI文件名; 然后他们可以将该注册表值更改为"%SystemRoot%\ System32\msiexec.exe""%1"%*`以允许在`cmd.exe`中指定`/ x`开关,然后右键单击MSI访问(至少)GUI中的安装选项.

3> 小智..:

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

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

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

推荐阅读
家具销售_903
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有