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

Posted on 2005-04-11
Medium Priority
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

ID: 13755373
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 22

Accepted Solution

JesterToo earned 2000 total points
ID: 13759119
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


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 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