Option Explicit
Const HKLM = &H80000002
Const APPS = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Dim reg, shell, keys, subkey, display, command, app, selection, result, path, regex, candidates
If WScript.Arguments.Count <> 1 Then WScript.Quit 64
selection = LCase(WScript.Arguments(0))
If selection <> "list" And selection <> "avira" And selection <> "ati" And selection <> "super" Then WScript.Quit 64
Set shell = CreateObject("WScript.Shell")
Set reg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Set regex = New RegExp
regex.IgnoreCase = True
regex.Pattern = "^(Avira |ATI |Catalyst Control Center|SUPERAntiSpyware)|antivirus|antimalware|security essentials|spybot|mcafee|norton|kaspersky|avast"
Set candidates = CreateObject("Scripting.Dictionary")
reg.EnumKey HKLM, APPS, keys
If IsArray(keys) Then
    For Each subkey In keys
        path = APPS & "\" & subkey
        reg.GetStringValue HKLM, path, "DisplayName", display
        If Not IsNull(display) Then
            If regex.Test(display) Then
                If selection = "list" Then WScript.Echo "INSTALLED " & display
                app = ""
                If InStr(1, display, "Avira AntiVir Personal", vbTextCompare) = 1 Then app = "avira"
                If subkey = "All ATI Software" And display = "ATI - Software Uninstall Utility" Then app = "ati"
                If display = "SUPERAntiSpyware Free Edition" Then app = "super"
                If app <> "" Then
                    If candidates.Exists(app) Then
                        WScript.Echo "More than one uninstall entry for " & app
                        WScript.Quit 2
                    End If
                    reg.GetStringValue HKLM, path, "UninstallString", command
                    If IsNull(command) Then reg.GetExpandedStringValue HKLM, path, "UninstallString", command
                    If Not IsNull(command) Then
                        If app = "ati" Then
                            command = Chr(34) & Replace(command, Chr(34), "") & Chr(34)
                        ElseIf app = "super" Then
                            If InStr(1, command, "msiexec.exe /x{", vbTextCompare) = 1 Then
                                command = command & " /qb! REBOOT=ReallySuppress"
                            End If
                        End If
                        candidates.Add app, command
                    End If
                End If
            End If
        End If
    Next
End If
If selection = "list" Then
    WScript.Echo "PACKAGE AUDIT DONE"
    WScript.Quit 0
End If
If Not candidates.Exists(selection) Then
    WScript.Echo "NO VENDOR UNINSTALL ENTRY " & selection
    WScript.Quit 3
End If
WScript.Echo "START UNINSTALL " & selection
command = shell.ExpandEnvironmentStrings(candidates(selection))
WScript.Echo command
result = shell.Run(command, 1, True)
WScript.Echo "UNINSTALL RETURNED " & result & " " & selection
WScript.Quit result
