VBScript to find software in the registry and then run the uninstall string
-
vendredi 23 juillet 2010 16:19
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.
Toutes les réponses
-
vendredi 23 juillet 2010 17:27Modérateur
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- Proposé comme réponse TRBoomer vendredi 12 avril 2013 00:56
-
vendredi 23 juillet 2010 17:46Modérateur
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- Marqué comme réponse joshlschmidt lundi 26 juillet 2010 12:55
-
lundi 26 juillet 2010 12:56Wow thanks for the quick responses. These are just what I was looking for.
-
vendredi 17 février 2012 16:16I tried the Script but it only shows the product ID. Can someone provide the syntax to execute the uninstall command please?
Robert
-
vendredi 17 février 2012 16:29Modérateur
Hi,
This thread is already marked answered. If you have a scripting question, please start a new thread; thanks.
Bill
-
vendredi 12 avril 2013 00:57I think this is a good mod to Tom's answer but Tom posted the answer.
-
vendredi 12 avril 2013 00:59Thanks for posting this. The example is going to help me change a lot of programs to simplify them and make them run better.

