msiexec
is command prompt software that installs an MSI program. 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.
But in order to uninstall the MSI file, it seems you have to call the msiexec
program and give it a /x
or /uninstall
.
How can I uninstall an MSI from the command line without using the msiexec
routine?
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.
"Babble, Babble - Over": Sections 1, 2 and 3 are 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.
If you have problems uninstalling altogether and are looking for an alternative to the deprecated MsiZap.exe and / 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.
Newer list of cleanup approaches: Cleaning out broken MSI uninstalls.
If you think MSI and Windows Installer is more trouble than it's worth, you might want to read about the corporate benefits of using MSI files.
Installscript MSI setups 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.
Some MSI files are installed as part of bundles via mechanism such as Burn (WiX Toolkit) or InstallShield Suite projects. This can make uninstall slightly different from what is seen below. Here is an example for InstallShield Suite projects.
Be aware that running uninstall silently or interactively can 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
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.
Using the original MSI
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:
Settings Interface (Windows 8 / 10):
Apps & Features
. Select entry and uninstall.ms-settings:appsfeatures
and press EnterUsing msiexec.exe command line (directly or via a batch file)
/qn
to make the uninstall run in silent mode. This is how an uninstall runs when triggered from the add/remove applet.Option 3.1: Basic interactive uninstall (access to original MSI file):
msiexec.exe /x "c:\filename.msi"
Option 3.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.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 3.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 slow because 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 3.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.exe from MSDN. Here is the Technet version.
Using the cached MSI database in the super hidden cache folder
get-wmiobject Win32_Product | Format-Table Name, LocalPackage -AutoSize
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?
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\"");
}
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
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++)
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.
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).
Below you will find a C++ snippet showing how to uninstall Orca, 10.1.17134.12
by product code using a call to the MsiConfigureProductEx function. To uninstall another product replace the GUID specified for prodcode
with 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?
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.
#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 2017 as of September 2018:
Create a new "Windows Console Application" from Visual C++ => Windows Desktop.
Copy and paste the above code into your main CPP file (replacing whatever is there).
That should be it to be able to run the code. Maybe set a breakpoint, build and run.