View Full Version : Removing old installs

10-01-2010, 02:44 PM
Just thought I'd pass this along...
I created a simple VBS custom action to uninstall an application. I needed this because a previous installer for an application that I updated did a very poor job and created wrong folders, wrong names, etc. To make it even more of a challenge, over time this was also done under several different GUIDs.
So here is a relatively simple VBS that will run the uninstaller (in quiet mode) for an application as long as you know the name of the application (as it would appear in the install/uninstall list in Windows).

Function Uninstall '<-- the function to call in InstallShield
Uninstall_Old_APP "my_app_to_uninstall" '<-- change this to the application you want to remove
End Function

Function Uninstall_Old_APP(AppToRemove)
const HKEY_LOCAL_MACHINE = &H80000002
Dim oReg, strKeyPath, SubKeys, subkey, strComputer, strValueName, strValue, wshShell
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strValueName = "DisplayName"
strComputer = "."

Set wshShell = CreateObject("WScript.Shell")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, SubKeys

For Each subkey In SubKeys

oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strValueName, strValue

If LCase(strValue) = LCase(AppToRemove) Then
'run the uninstaller for subkey (the application GUID)
wshShell.Run "msiexec /x " & subkey & " /q", 1, true
Exit Function
End If

End Function

Just call Uninstall and set the parameter of Uninstall_Old_APP to the application name you want uninstalled. This will iterate through all the GUIDS in the Control Panels uninstall list - and if it finds one with an application named the same as what was provided - it will run the MSI uninstaller in quiet mode.
For the application I needed this for it only takes a few seconds to run - so I was very happy with the results.