Script Tips

Automated Uninstall

The Win32_Product class is useful in many ways, including uninstalling Windows Installer-managed apps.

One cool WMI class in Windows XP is Win32_Product. Try it: Select Start, Run and type Wbemtest, and click OK. Click Connect, enter root\cimv2 for the namespace, and click OK. Then click Query and type Select * From Win32_Product. Give it a sec and you’ll see a list of every Windows Installer-managed application on your machine. Very nifty, and you can write a script that’ll even uninstall applications. Here's a script that will uninstall the application named "Toshiba Registration":

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set cApps = oWMI.ExecQuery("Select * From " & _
   "WHERE Name = 'Toshiba Registration'")
For Each oApp in cApps
   oApp.Uninstall
Next

Naturally, you can tweak this script to uninstall whatever you want, to display a list of all installed applications (eliminate the WHERE clause and replace oApp.Uninstall with WScript.Echo oApp.Name), and so forth.

A problem is that running this script on a Windows 2003 box results in an "unknown class" error, because by default the Win32_Product class -- indeed, the entire Windows Installer WMI provider -- doesn’t exist on Windows 2003. It’s only a short-term problem, though, because you can install it: Open Add or Remove Programs and get into the Add/Remove Windows Components wizard. Under Management and Monitoring Tools, you’ll find the WMI Windows Installer Provider. Once installed, you can perform nifty tricks with Win32_Product on Windows 2003 boxes, too.

We've provided a sample script that you can test this with; to get it, click here.

About the Author

Don Jones is a multiple-year recipient of Microsoft’s MVP Award, and is an Author/Evangelist for video training company Pluralsight. Don is also a co-founder and President of PowerShell.org, a community dedicated to Microsoft’s Windows PowerShell technology. Don has more than two decades of experience in the IT industry, and specializes in the Microsoft business technology platform. He’s the author of more than 50 technology books, an accomplished IT journalist, and a sought-after speaker and instructor at conferences worldwide. Reach Don on Twitter at @concentratedDon, or on Facebook at Facebook.com/ConcentratedDon.

comments powered by Disqus
Most   Popular

SharePoint Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.