VBScript to find software in the registry and then run the uninstall string
-
Friday, July 23, 2010 4:19 PM
I have been searching for code for this all morning. I have yet to find what I am looking for. I am trying to write a script to search hklm\software\microsoft\windows\currentversion\uninstall for software (adobe reader for instace) no matter the version. Once it finds the application I would like the script to pull the value of the uninstallstring key and then run it to remove the program.
I have been beating my head against code that enumerates the keys, but cant get it to actually find the product.
Any help would be greatly appreciated.
All Replies
-
Friday, July 23, 2010 5:27 PMModerator
Maybe somthing like this will help (run it at the command prompt with the cscript host) ...
const HKEY_CLASSES_ROOT = &H80000000
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_USERS = &H80000003
const HKEY_CURRENT_CONFIG = &H80000004
const HKEY_DYN_DATA = &H80000005
strComputer = "."
set oWsh = createobject("wscript.shell")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
strKeyPath = "software\microsoft\windows\currentversion\uninstall" ' Root level
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
sMatch = "Adobe"
For Each subkey In arrSubKeys
on error resume next
sDisplayName = oWsh.Regread("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName")
if err.number = 0 then
on error goto 0
if instr(sDisplayName, sMatch) > 0 then
sUninstall = oWsh.Regread("HKLM\" & strKeyPath & "\" & subkey & "\UnInstallString")
wsh.echo subkey, vbCRLF, sDisplayName, vbCRLF, sUnInstall, vbCRLF, vbCRLF
end if
end if
Next
on error goto 0
Tom Lavedas- Proposed As Answer by TRBoomer Friday, April 12, 2013 12:56 AM
-
Friday, July 23, 2010 5:46 PMModerator
Looks like it is possible for there to be no UnInstallString key. When I tested the script there were two keys for "Adobe Photoshop Elements 5.0", one of which did not have the UnInstallString key. I modified Tom's script as follow:
const HKEY_CLASSES_ROOT = &H80000000 const HKEY_CURRENT_USER = &H80000001 const HKEY_LOCAL_MACHINE = &H80000002 const HKEY_USERS = &H80000003 const HKEY_CURRENT_CONFIG = &H80000004 const HKEY_DYN_DATA = &H80000005 strComputer = "." set oWsh = createobject("wscript.shell") Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\default:StdRegProv") strKeyPath = "software\microsoft\windows\currentversion\uninstall" ' Root level oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys sMatch = "Adobe" For Each subkey In arrSubKeys on error resume next sDisplayName = oWsh.Regread("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName") if err.number = 0 then on error goto 0 if instr(sDisplayName, sMatch) > 0 then On Error Resume Next sUninstall = oWsh.Regread("HKLM\" & strKeyPath & "\" & subkey & "\UnInstallString") If Err.Number = 0 Then wsh.echo subkey, vbCRLF, sDisplayName, vbCRLF, sUnInstall, vbCRLF, vbCRLF Else wsh.echo subKey, vbCrLf, sDisplayName, vbCrLf, "<None>", vbCrLf, vbCrLf End If On Error GoTo 0 end if end if Next on error goto 0I trap the error so if the key does not exist I output "<None>".
Richard Mueller
MVP ADSI- Marked As Answer by joshlschmidt Monday, July 26, 2010 12:55 PM
-
Monday, July 26, 2010 12:56 PMWow thanks for the quick responses. These are just what I was looking for.
-
Friday, February 17, 2012 4:16 PMI tried the Script but it only shows the product ID. Can someone provide the syntax to execute the uninstall command please?
Robert
-
Friday, February 17, 2012 4:29 PMModerator
Hi,
This thread is already marked answered. If you have a scripting question, please start a new thread; thanks.
Bill
-
Friday, April 12, 2013 12:57 AMI think this is a good mod to Tom's answer but Tom posted the answer.
-
Friday, April 12, 2013 12:59 AMThanks for posting this. The example is going to help me change a lot of programs to simplify them and make them run better.

