?
Solved

Need a script to uninstall multiple versions of same software execpt one

Posted on 2009-03-30
4
Medium Priority
?
378 Views
Last Modified: 2012-06-27
I have an application with multiple versions I need to uninstall but leave the correct version intact. I need a script that checks for the appp name and app version and unintalls all but the correct version.

tx!
0
Comment
Question by:geewizzz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
rejoinder earned 2000 total points
ID: 24025842
Modify the script below to match your files name and version number.
I recomend you uncomment the echo command in the loop and comment out the uninstallByGuid line so you can double check that all the right files are being targeted.
To tweak, the select statement will have to be modified a little.
strComputer = "."
strSoftName = "Adobe Acrobat"
strVersion  = "9.0"
 
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product Where Name like '" & strSoftName & "%' AND Version <> '" & strVersion & "'")
For Each objItem in colItems
    'WScript.Echo objItem.IdentifyingNumber
    WScript.Echo UninstallByGuid(objItem.IdentifyingNumber) 
Next
 
Function UninstallByGUID(sGUID)   
    Set oWMIroot = SWBemlocator.ConnectServer(strComputer,"root\CIMV2") 
    Set oWMIColl = oWMIroot.ExecQuery("Select * FROM Win32_Product Where IdentifyingNumber = '" & sGUID & "'") 
    For Each oWMIval In oWMIColl
        oWMIval.Uninstall() 
        UninstallByGUID = "Removal of " & oWMIval.Name & " complete (" & err.number & ")"
    Next 
    If UninstallByGUID = "" Then
        UninstallByGUID = "Application GUID not found."
    end if
End Function
 
msgbox ("All done")

Open in new window

0
 

Author Comment

by:geewizzz
ID: 24028979
Fantastic, tx for the quick response!
Nice script, very clean. I had figured it out last night but yours way better!
One issue I am having with it is some apps installs(Java) dont have 'Version' info. This uninstalled all versions of Java except the one I entered PLUS the one that doesnt have version info. I assume we would incorporate another line, something like ....
If Version = ""
then....

Any ideas?

FYI, I also have another question open - looking for a script that will delete a locked file???  500 pts and no one has solved it. I figure if a tool like 'Unlocker' can do it- why not a script???
0
 
LVL 14

Expert Comment

by:rejoinder
ID: 24054247
Thanks very much.
I will see what can be done about the version number issue.  I will get back to you soon.
Can you post the link to the other question and I will check it out.
0
 
LVL 14

Expert Comment

by:rejoinder
ID: 24054430
That might work.  The block of code would look like this...
For Each objItem in colItems
    if objItem.Version <> "" then
        'WScript.Echo objItem.IdentifyingNumber
        WScript.Echo UninstallByGuid(objItem.IdentifyingNumber)
    end if
Next
It would need testing at your end to see if it is giving you the desired results.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question