Friday, January 6, 2012

How to Uninstall Software on Remote Computers Using a Command Line


!±8± How to Uninstall Software on Remote Computers Using a Command Line

WMIC (Windows Management Instrumentation Command-Line) is a potent tool that often doesn't see much use due to the lack of (easily accessible) documentation available. For this technical article for IT professionals, we'll be using WMIC with domain admin credentials to crawl through a list of nodes (PCs/Laptops) and uninstall an example program without interrupting the user.

1. Load up a command shell with appropriate access permissions

Though a WMIC instruction can be given appropriate credentials prior to operation, it is typically best-practice to avoid clear-text typing the password (who is that looking over your shoulder;)). We'll execute the runas command like the following:

Runas /user:DomainAdminAccount@DOMAIN cmd

... which will prompt us for the credentials of our DomainAdminAccount. If authenticated, we'll be handed a command shell running as the Admin.

2. Step into WMIC

One of the nice features of WMIC is that it may be run from any machine. With our admin command shell, we're going to enter the WMIC command followed by enter. (Note: We could have jumped into WMIC directly from the runas command... this just breaks out the steps)

3. Verify Program Installation (an optional informative step)

With our WMIC prompt, we can ask many questions of a node (or nodes) and receive some nicely formatted replies. Though formatting the replies 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:COMPUTERNAME product get name,version,vendor

This command asks WMI to reply with a list including the Name, Version, and Vendor of all compliant software installations.

If you would like to filter for a specific product, you may do so. Here's an example scanning a networked machine for all installed applications from the vendor "Apple, Inc"

>/node:ANOTHEREXAMPLE product where vendor="Apple Inc." get name,vendor

A small hint if you have special characters like '-' or '/' in the computer name you need to use ' ' characters in order to get information from client)

Here is how you use wildcards in your search:

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

e.g.: /node:ComputerXYZ product where "vendor like 'adobe%'" get name,version,identifyingNumber )

4. Call for the Uninstallation

So we can make a call to the WMI interface to uninstall a particular product... let's pick on the MobileMe Control Panel from our previous example. The command:

>/node:EXAMPLE product where name="MobileMe Control Panel" call uninstall

... will prompt you for confirmation in the following (long) format:

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

.. to which you must reply 'y' if you wish to uninstall. WMI compliant software will run the default uninstallation procedures without the user needing to do anything (they receive no prompts etc).

5. Call Uninstall for a List of Machines (an optional informative step)

Let's assume you just got word that Adobe Reader has a serious flaw in it's old version. In a panic, you asked all your users to blindly install the new version of Adobe reader straight from Adobe's site. Thankfully, they all managed to do so... however you've received 3 tickets so far about an Acrobat.com icon on the desktop.

You have a flat text file of all your computer's names stored in c:computers.txt. You pop open a WMIC shell with 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 invalid (eg:machine is turned off) and those that don't meet the criteria. You'll need to confirm 'y' that you want to uninstall on every node... but that may be a small price to pay for not needing to run around to every machine.

Conclusion

Hopefully you've been intrigued by the potency of WMIC. Though the command-line use of the uninstall call may not be commonly needed with software management tools, AD, etc... it can sometimes be the best way to accomplish a task quickly without disturbing your user(s).

Learn more about WMIC at their official web site.


How to Uninstall Software on Remote Computers Using a Command Line

Purchasing Hp Slim Pc Saved Leaf Shredder Upright Small Freezer Better Than




No comments:

Post a Comment


Twitter Facebook Flickr RSS



Fran�ais Deutsch Italiano Portugu�s
Espa�ol ??? ??? ?????







Sponsor Links