msiexec
是安装MSI程序的命令提示软件。但我发现只需在命令行输入MSI文件的名称,就可以从命令行安装MSI文件。
但是为了卸载MSI文件,你似乎必须调用msiexec
程序并给它一个/x
或/uninstall
。
如何在不使用msiexec
例程的情况下从命令行卸载MSI?
简短的回答:你做不到。使用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文件时实际使用的命令行。
有许多方法可以卸载MSI包。这是作为“参考”。
总之,您可以通过以下方式卸载:msiexec.exe,ARP,WMI,PowerShell,部署系统(如SCCM,VBScript / COM Automation,DTF)或隐藏的Windows缓存文件夹,以及下面介绍的其他一些选项。
前几段提供了重要的MSI花絮,然后有14个部分有不同的方法来卸载MSI文件。 PUH。
“Babble,Babble - Over”:第1,2和3节是正常的卸载方法(因此推荐)。
Personally I use option 3 or 5 from section 3
(两个选项都带有日志记录,但选项5也以静默方式运行)。如果你很忙,可以跳过所有的唠叨,然后选择其中一个 - 它将完成工作。
如果您在完全卸载时遇到问题,并且正在寻找已弃用的替代方案 MSIZAP.EXE 和/或Windows Installer CleanUp Utility( MSICUU2.exe ),你可以尝试新的FixIt tool from Microsoft(or the international page)。可能显然也适用于其他安装问题。
如果你认为MSI和Windows Installer比它的价值更麻烦,你可能想了解一下the corporate benefits of using MSI files。
Installscript MSI设置通常包含在setup.exe文件中。要阅读有关用于卸载此类设置的参数的更多信息,请参阅以下链接:setup.exe pdf reference sheet,Setup.exe and Update.exe Command-Line Parameters。
一些MSI文件通过Burn(WiX Toolkit)或InstallShield Suite项目等机制作为bundle的一部分安装。这可以使卸载与下面的内容略有不同。这是an example for InstallShield Suite projects。
请注意,以静默方式或交互方式运行卸载会导致不同的结果(!)。有关为何会出现这种情况的相当冗长的描述,请阅读以下文章:Uninstall from Control Panel is different from Remove from .msi
如果您在尝试卸载时意外地要求提供原始安装介质,请阅读以下答案:Why does MSI require the original .msi file to proceed with an uninstall?以及下面第12节中的一些重要技术细节。
如果您安装了CCleaner或类似的清理工具,可以跳转到第11节。
如果卸载完全失败(无法运行),请参阅下面的第12和13节,了解使用system restore和/或清理工具“撤消”安装的可能方法。
Using the original MSI
Using the old ARP Applet OR new Windows 8/10 Settings Interface
ARP
= Add / Remove Programs Applet
(appwiz.cpl
)
Windows 10 Settings Interface
=>相同操作的新shellApps & Features
。选择进入和卸载。
以这种方式调用卸载时出现一些错误报告。如果看到,请在下方添加评论。
Try this answer as well
一般提示:尝试禁用防病毒软件并重试。Using msiexec.exe command line (directly or via a batch file)
/qn
以使卸载以静默方式运行。这是从添加/删除applet触发时卸载的运行方式。
选项1:基本交互式卸载(访问原始MSI文件):
msiexec.exe /x "c:\filename.msi"
选项2:通过产品GUID进行基本交互式卸载(无法访问原始MSI文件 - here is how to find the product 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:使用刷新的详细日志文件进行交互式卸载(verbose, flush to log option - 连续写日志,可能非常慢):
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选项使卸载变慢,因为日志文件是连续写入而不是批量写入。这可确保在安装程序崩溃时不会丢失日志缓冲区。
换句话说,如果您的安装程序崩溃并且详细日志文件中没有有用的信息,请启用此选项。删除感叹号以关闭flush to 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:How can I find the product GUID of an installed MSI setup?(如果您没有在卸载命令中指定的原始MSI,则用于卸载)。Using the cached MSI database in the super hidden cache folder
get-wmiobject Win32_Product | Format-Table Name, LocalPackage -AutoSize
Using
PowerShell
$app = Get-WmiObject -Class Win32_Product -Filter "Name = 'YOUR_APP'"
$app.Uninstall()
Using the .NET DTF Class Library
(the WiX toolkit的一部分) using Microsoft.Deployment.WindowsInstaller;
public static void Uninstall( string productCode)
{
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\"");
}
Using the
Windows Installer Automation API
Set installer = CreateObject("WindowsInstaller.Installer")
installer.InstallProduct "product.msi", "REMOVE=ALL REBOOT=ReallySuppress"
Set installer = Nothing
Using a
Windows Installer major upgrade
Using Deployment Systems / Remote Administration Systems
Using WMI - Windows Management Instrumentation
Win32_Product.Install
调用安装
可以通过Win32_Product.Uninstall
调用卸载Using a third-party tool such as
ccleaner
or similar
Using a cleanup tool such as
msizap
or similar
Using
system restore
("installation undo" - last resort IMHO)
Windows Installer Functions (C++)
为了完整性,我想我们应该提到它的核心 - 从金属方面来说:the Win32 Windows Installer API functions。这些很可能是大多数(如果不是全部)上面列出的所有其他方法所使用的功能。它们主要用于直接处理MSI作为技术的应用程序或解决方案。
在serverfault.com上有一个答案可能是a summary of the different programmatic approaches for uninstalling(COM自动化,.NET,Win32安装程序功能)。
下面是一个C ++代码片段,展示了如何通过调用Orca, 10.1.17134.12
按产品代码卸载MsiConfigureProductEx function。要卸载其他产品,请将为prodcode
指定的GUID替换为您的产品。要查找产品代码,请参阅以下答案:How can I find the product GUID of an installed MSI setup?
卸载将在完整的GUI模式下进行。要以静默模式或其他GUI模式(简化,基本等)运行,请参阅:MsiSetInternalUI function。
#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
}
截至2018年9月,使用最新版本的Visual Studio 2017制作并测试了该片段:
还要记住,可以使用WMIC命令启动卸载:
wmic product get name
- >这将列出所有已安装应用的名称
wmic product where name='myappsname' call uninstall
- >这将卸载该应用程序。
msi
文件扩展名映射到msiexec(在命令提示符下键入.txt文件名的方式相同,启动Notepad / default .txt
文件处理程序以显示文件)。
因此,输入带有.msi扩展名的文件名实际上以MSI文件作为参数运行msiexec并采取默认操作install。因此,卸载要求您使用卸载开关调用msiexec以取消安装。
wmic product get name
只是让cmd卡住......几分钟后仍然闪烁着
在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
中,如果您可以找到包含您尝试安装的软件名称的文件夹(而不是使用ProductCode命名的文件夹),则UninstallString指向应用程序自己的卸载程序C:\Program Files\Zune\ZuneSetup.exe /x
我会尝试以下语法 - 它适用于我。
msiexec /x filename.msi /q
我假设当你在命令行输入int file.msi时,Windows会自动为你调用msiexec file.msi。我假设这是因为当你输入picture.png它会调出默认的图片浏览器。