How to uninstall software on remote computers using a command line

WMIC (Windows Management Instrumentation Command-Line) is a powerful tool that often does not get much use due to the lack of available (easily accessible) documentation. For this technical article for IT professionals, we will use WMIC with domain administrator credentials to crawl a list of nodes (PCs / Laptops) and uninstall a sample program without interrupting the user.

1. Load a command shell with the appropriate access permissions.

Although a WMIC instruction can be given the proper credentials before operation, it is generally good practice to avoid typing the password in clear text (who’s looking over their shoulder;)). We will execute the runas command as follows:

Runes / user: DomainAdminAccount @ DOMAIN cmd

… which will ask us for the credentials of our DomainAdminAccount. If we are authenticated, we will be given a command shell that will run as administrator.

2. Login to WMIC

One of the nice features of WMIC is that it can be run from any machine. With our admin command shell, we will enter the WMIC command followed by enter. (Note: we could have jumped to WMIC directly from the runas command … this just breaks down the steps)

3. Verify the installation of the program (an optional informational step)

With our WMIC indicator, we can ask a node (or nodes) a lot of questions and receive some answers in a nice format. Although formatting responses is beyond the scope of this “How To”, much more information can be found on the Internet.

So let’s find out if a particular node even has our target software:

> / node: product get name COMPUTERNAME, version, vendor

This command asks WMI to respond with a list that includes the name, version, and vendor of all supported software installations.

If you want to filter for a specific product, you can. Below is an example of a network machine scan for all installed applications from the provider “Apple, Inc”

> / node: ANOTHER PRODUCT EXAMPLE where vendor = “Apple Inc.” get name, provider

A little hint if you have special characters like ‘-‘ or ‘/’ in the computer name, you should use the characters ” to get customer information)

This is how you use wildcards in your search:

Surround the similar phrase in double quotes and your search criteria in single quotes and use% as the wildcard symbol.

for example: / node: ComputerXYZ product where “vendor like ‘adobe%'” gets the name, version, identification number)

4. Call for uninstall

Then we can make a call to the WMI interface to uninstall a particular product … let’s choose the MobileMe Control Panel from our previous example. The command:

> / node: PRODUCT EXAMPLE where name = “MobileMe Control Panel” calls uninstall

… it will ask you for confirmation in the following format (long):

Run (EXAMPLEROOTCIMV2: Win32_Product.IdentifyingNumber = “{6DA9102E-199F-43A0-A36B-6EF48081A658}”, Name = “MobileMe Control Panel”, Version = “2.1.0.24”) -> Uninstall () (Y / N /?) ?

.. to which you should answer ‘and’ if you want to uninstall. The WMI-compliant software will run the default uninstall procedures without the user having to do anything (no prompts, etc.).

5. Call Uninstall for a list of machines (an optional informational step)

Suppose you just learned that Adobe Reader has a serious flaw in its old version. In a panic, he asked all his users to blindly install the new version of Adobe Reader directly from the Adobe site. Fortunately, everyone managed to do it … however, so far you have received 3 tickets about an Acrobat.com icon on the desktop.

You have a plain text file with all your computer’s names stored in c: computers.txt. Open a WMIC shell with the appropriate permissions and enter the following command:

> / node: @ “c: computers.txt” product where name = “Acrobat.com” call uninstall

Which iterates through your list, skipping nodes that are not valid (ex: the machine is powered off) and those that do not meet the criteria. You will have to confirm ‘y’ that you want to uninstall on each node … but that may be a small price to pay for not having to run on all machines.

Conclution

Hopefully, the power of WMIC has intrigued you. Although using the uninstall call command line may not be commonly required with software management tools, AD, etc., it can sometimes be the best way to quickly accomplish a task without disturbing your users.

Find out more about WMIC on its official website.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *