Quantcast
Channel: Catapult Systems » VBScript
Viewing all articles
Browse latest Browse all 5

Uninstall Multiple Versions of an Application with One Script

$
0
0

I recently ran into a situation where I needed to uninstall Microsoft Office Live Meeting 2007 through SCCM. Normally this would not be an issue, but the environment I was working had multiple versions installed. Therefore I was unable to run the msiexec /x {product code} command, because each version had it own product code.

This left me with a couple of options.  I could make a separate uninstall for each version. This would be very cumbersome and require being able to determine the product code for every potentially installed version. Or I could write a VBScript that would find the installed version and perform the uninstall. I choose to create the VBScript.

Even though each version has its own product code, they all contain the same upgrade code. So, using the upgrade code I was able to write a script that will query the Win32_Property class and return the product code based on the upgrade code. The script will then execute the msiexec /x {product code} command to perform the uninstall.

I have tested this with four different versions and it worked for each of them. The good thing about this, is you can use this for pretty much any product that uses the upgrade code in the install MSI. You will just need to change the upgrade code in line 13.

strComputer = <span class="str">&quot;.&quot;</span> 
<span class="kwrd">Set</span> WshShell = CreateObject(<span class="str">&quot;Wscript.Shell&quot;</span>)
<span class="kwrd">Set</span> objWMIService = GetObject(<span class="str">&quot;winmgmts:&quot;</span> _ 
    &amp; <span class="str">&quot;{impersonationLevel=impersonate}!\\&quot;</span> &amp; strComputer &amp; <span class="str">&quot;\root\cimv2&quot;</span>) 

<span class="kwrd">On</span> <span class="kwrd">Error</span> <span class="kwrd">Resume</span> <span class="kwrd">Next</span> 

<span class="kwrd">Set</span> colSoftware = objWMIService.ExecQuery _ 
    (<span class="str">&quot;Select * from Win32_Property Where Property = 'UpgradeCode'&quot;</span>) 

<span class="kwrd">For</span> <span class="kwrd">Each</span> objSoftware <span class="kwrd">in</span> colSoftware 
    <span class="rem">'Check for Microsoft Office Live Meeting 2007 - Uninstall if found</span>
    <span class="kwrd">If</span> objSoftware.Value = <span class="str">&quot;{574BB76B-6E89-497C-906F-2CBB7EC6ABB9}&quot;</span> <span class="kwrd">Then</span>
    strCMD = <span class="str">&quot;MsiExec.exe /x &quot;</span> &amp; objSoftware.ProductCode &amp; <span class="str">&quot; /qn&quot;</span>
    objExec = WshShell.Run(strCMD,1,<span class="kwrd">True</span>)
    <span class="kwrd">If</span> objExec &lt;&gt; 0 <span class="kwrd">Then</span>
        WScript.Quit objExec
    <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">End</span> <span class="kwrd">If</span> 
<span class="kwrd">Next</span>
WScript.Quit 0

 

This script can easily be changed to add logging and additional error checking as needed.


Viewing all articles
Browse latest Browse all 5

Trending Articles