<

Software Uninstallation using WMIC command line

Published on
37,918 Points
24,518 Views
4 Endorsements
Last Modified:
Approved
Community Pick
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the same question.

Now every administrator knows about uninstalling software from the Add/Remove Programs (or Programs and Features) tab in Control Panel.  This may work well if you have to uninstall from just a handful of computers, but what about if you are responsible for managing hundreds or thousands of computers?


The MsiExec / GUID Method

One answer that I see often recommended is to use the registry uninstall strings, as described here:
    Uninstall Registry Key
    http://msdn.microsoft.com/en-us/library/aa372105(VS.85).aspx

Basically, you open up RegEdit, navigate to
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
and look around for an entry matching the software you want to uninstall.

Once found, the registry key should have an UninstallString entry that should contain the MSIEXEC command that uses the GUID of the program to uninstall it.

I have used this many times in the past and this method does work to get software uninstalled. I do have some issues with it however, the first being that the GUID method is not very user friendly. Looking at the following GUID for Office 2007 Professional {90120000-0011-0000-0000-0000000FF1CE} at first glance it isn't obvious what software product this is (although Microsoft's use of hex digits to spell out "office" is clever).

Utilizing the GUID found in the registry you would end up with an uninstall string like:
MsiExec.exe /x {90120000-0011-0000-0000-0000000FF1CE} /qn

Open in new window


If you are in a situation with multiple administrators, this could be difficult for those who did not write the script to know what program it is supposed to remove.

Another limitation that I have run into using the GUID uninstall method is that minor version changes of the same software can have different GUIDs. A software product version 7.1.2 may have a different GUID from that of version 7.1.5.  This would require multiple MSIEXEC commands to address these software installations with different GUIDs.


The WMIC Method

Recently, I have been using a different technique to uninstall software. My new preferred approach utilizes the WMIC command.  WMIC can be helpful in many ways for administrators, however I'm not going to go into heavy explanation of all the features in this article.  If you aren't familiar and want to know more this TechNet article will give you a very good primer:

    WMIC - Take Command-line Control over WMI
    http://technet.microsoft.com/en-us/library/bb742610.aspx

One of the key benefits I have found using WMIC is that the commands are much simpler than the MSIEXEC method mentioned above. Using WMIC there is no more searching the registry, finding GUIDs, and no more confusing MSIEXEC commands. The commands issues are much more human friendly as you will see in the examples below.

Example:
Using WMIC to uninstall a software product by exact name

Open up a command prompt and type the following line:
WMIC product get name

Open in new window

If this is your first time running WMIC it will take a second to automatically install itself.  This command will return a list of all of the software installed on that particular machine.

Once you have found the name of the software you would like to remove, copy the name exactly as it appears in the output.  And modify the following command's ProductName section.
    WMIC product where name="ProductName" call uninstall
For instance...

Hitting enter will begin the uninstallation process for the desired software.  The uninstallation will automatically run silently with no user interaction.


Example:
Using WMIC to uninstall a software product by wildcard name

It is possible to use the same WMIC command with wildcards to uninstall multiple versions of a software.  For example Adobe Reader versions 7, 8, and 9 could be installed on machines in your organization.  To remove all of these using the same command, you would use the LIKE operator and the % character wildcard, as in this command:


Example:
Using WMIC to uninstall software on a remote machine by exact name

WMIC wouldn’t be quite as useful if you had to run the commands individually on each machine, so they provided an option to target a remote machine as well. Simply replace computername with the desired target computer.

It is also possible to target multiple computers.  Simply separate the computername strings with commas.


Example:
Using WMIC to uninstall software on a remote machine by wildcard search

You can combine the two.  For instance, this command line uninstalls multiple versions of Adobe Reader and it does it on a remote computer:



Tip:
Using WMIC in a batch file (startup script)

This is probably the tip administrators will find the most useful.  The commands mentioned above target a single machine locally, a single remote machine, and a specified group of remote machines all entered manually.  In a large environment you will not want to manually enter all the computernames. WMIC can also be called from within a standard batch file.

If using WMIC in a batch file you will want to use the local commands since each machine will be running the batch file individually.  To have WMIC successfully uninstall a product, you can set the script as a computer startup script. Since startup scripts run under the SYSTEM context, it will have the administrative rights that your users don’t have.
 
There are a million different ways to use the WMIC command line and this is only one application. If you found your way here I hope this was of some assistance to you. If you have any questions please feel free to post them and I will do my best to answer them.        
4
Comment
Author:Joseph Daly
3 Comments
 
LVL 35

Author Comment

by:Joseph Daly
Thanks
0
 
LVL 2

Expert Comment

by:petaganayr
I find this post very useful though, I could no longer see the commands.
0
 

Expert Comment

by:Mike Thomson
I don't see he commands any more. Is there any way you can re-post them?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month