none
VBScript to find software in the registry and then run the uninstall string

    Frage

  • 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.

    Freitag, 23. Juli 2010 16:19

Antworten

  • 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 0
    
    

    I trap the error so if the key does not exist I output "<None>".

    Richard Mueller


    MVP ADSI
    • Als Antwort markiert joshlschmidt Montag, 26. Juli 2010 12:55
    Freitag, 23. Juli 2010 17:46

Alle Antworten

  • 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
    • Als Antwort vorgeschlagen TRBoomer Freitag, 12. April 2013 00:56
    Freitag, 23. Juli 2010 17:27
  • 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 0
    
    

    I trap the error so if the key does not exist I output "<None>".

    Richard Mueller


    MVP ADSI
    • Als Antwort markiert joshlschmidt Montag, 26. Juli 2010 12:55
    Freitag, 23. Juli 2010 17:46
  • Wow thanks for the quick responses.  These are just what I was looking for. 
    Montag, 26. Juli 2010 12:56
  • I tried the Script but it only shows the product ID. Can someone provide the syntax to execute the uninstall command please?

    Robert

    Freitag, 17. Februar 2012 16:16
  • Hi,

    This thread is already marked answered. If you have a scripting question, please start a new thread; thanks.

    Bill

    Freitag, 17. Februar 2012 16:29
  • I think this is a good mod to Tom's answer but Tom posted the answer.
    Freitag, 12. April 2013 00:57
  • Thanks for posting this. The example is going to help me change a lot of programs to simplify them and make them run better.
    Freitag, 12. April 2013 00:59