Need to use a VBScript to uninstall a non MSI program.

Posted on 2005-04-11
Last Modified: 2008-02-26
Hello Experts. First let me say I am not a programmer :P I need help tweaking an uninstall script I found here:

I've updated the strKeyPath to reference the correct program to uninstall and it works. The problem is if it runs after the uninstall has taken place. For example, a user logs in and the script runs and it does the uninstall successfully. The next time the user logs in and the script runs it returns the following error:

Line: 15
Char: 1
Error: Unable to wait for process.
Code: 80020009
Source: WshShell.Run

Is there a way to set an IF statement that checks the registry for the uninstall string for the particular program and if it exists to run the script otherwise kick out? Or you may know of a better way to accomplish this.

Also, I would like the script to check for 2 programs to uninstall. For example, first it will check to see if program1 is installed, if so it runs the commands to uninstall it. If not, it checks to see if program2 is installed. If so it runs the uninstall commands and if not it ends.

Thanks for your help,
Question by:boeye
    LVL 28

    Expert Comment

    May be as simple as adding:

    On Error Resume Next

    at the top of the script.  If an error occurs, it ignores it and continues on.  Unless you want to add special error handling in, this may be sufficient for your needs.
    LVL 20

    Accepted Solution

    Here is a modified version of the script you referenced.  It checks to see if it found an uninstallation path before trying to execute it.  Just change the indicated lines to match the registry keys for your apps.  You can extend this to more than two apps if you need by just cloning the 9 /10 pertinent lines but it might be better to create a subroutine of the common code and call it passing the RegKey values if you intend to uninstall several apps.

    const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
               strComputer & "\root\default:StdRegProv")
    Set WshShell = WScript.CreateObject("WScript.Shell")

    ' Uninstall first application...
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Acrobat 5.0" '<--- change as needed
    strValueName = "UninstallString"
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strUninstallFullPath
    If IsNull(strUninstallFullPath) Then
       ' wscript.echo "Uninstall path for app1 is null"
       ' the following line -y switch suppresses the confirmation question from poping up
       strUninstallFullPath=strUninstallFullPath & " -y"                                 '<--- change as needed
       WshShell.Run strUninstallFullPath,8,true
    End If

    ' Uninstall second application...
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SomeOtherApp"      '<--- change as needed
    strValueName = "UninstallString"
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strUninstallFullPath
    If IsNull(strUninstallFullPath) Then
       ' wscript.echo "Uninstall path for app2 is null"
       WshShell.Run strUninstallFullPath,8,true
    End If

    Set WshShell = Nothing
    Set oReg = Nothing


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now