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

xar*_*rzu 54 .net installation command-line windows-installer msiexec

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

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

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

Ste*_*mul 148

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"
      
      Run Code Online (Sandbox Code Playgroud)
    • 选项2:通过产品GUID进行基本交互式卸载(无法访问原始MSI文件 - 以下是如何查找产品GUID - 相同链接,如下所示):

       msiexec.exe /x {11111111-1111-1111-1111-11111111111X}
      
      Run Code Online (Sandbox Code Playgroud)
    • 选项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"
      
      Run Code Online (Sandbox Code Playgroud)
    • 选项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"
      
      Run Code Online (Sandbox Code Playgroud)
      • 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
      
      Run Code Online (Sandbox Code Playgroud)

      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
      
      Run Code Online (Sandbox Code Playgroud)

      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.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
Run Code Online (Sandbox Code Playgroud)

Enter image description here


5. Using PowerShell


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

    using Microsoft.Deployment.WindowsInstaller;

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

7. Using the Windows Installer Automation API


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


11. Using a third-party tool such as ccleaner or similar

Rog*_*mbe 48

简短的回答:你做不到.使用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. (3认同)
  • 不确定我同意[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中的安装选项. (2认同)

小智 31

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

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

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


归档时间:

查看次数:

248747 次

最近记录:

6 年,3 月 前