On Error Resume Next ' Uninstall Adobe Acrobat Only If Edition = 300 ' ============================================= Const HKEY_LOCAL_MACHINE = &H80000002 Const EDITION_REQUIRED = "300" strComputer = "." Set WshShell = WScript.CreateObject("WScript.Shell") Set objReg = GetObject( _ "winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") ' Get OS architecture ' =================== Err.Clear checkOSArch = WshShell.RegRead( _ "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE") returnValue = 0 If Err Then Err.Clear Else If LCase(checkOSArch) = "x86" Then strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" returnValue = RemoveAdobe(strKeyPath) Else strKeyPath64 = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" returnValue = RemoveAdobe(strKeyPath64) strKeyPath86 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" returnValue = RemoveAdobe(strKeyPath86) End If End If WScript.Quit returnValue ' =============================================================== ' Iterate uninstall registry keys and remove Adobe Acrobat safely ' =============================================================== Function RemoveAdobe(KeyPath) On Error Resume Next Set objReg = GetObject( _ "winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") Set shell = CreateObject("WScript.Shell") objReg.EnumKey HKEY_LOCAL_MACHINE, KeyPath, arrSubKeys If IsNull(arrSubKeys) Then Exit Function End If For Each Subkey In arrSubKeys Err.Clear strDisplayName = "HKEY_LOCAL_MACHINE\" & _ KeyPath & "\" & Subkey & "\DisplayName" displayName = "" displayName = WshShell.RegRead(strDisplayName) If Err.Number <> 0 Then Err.Clear Continue For End If ' Validate Adobe Acrobat product name If InStr(1, displayName, "Adobe Acrobat", vbTextCompare) <> 0 Then ' ----------------------------------------------------------------- ' NEW SECURITY HARDENING: ' Read Edition value and continue only if Edition = 300 ' ----------------------------------------------------------------- editionRegPath = "HKEY_LOCAL_MACHINE\" & _ KeyPath & "\" & Subkey & "\Edition" editionValue = "" Err.Clear editionValue = WshShell.RegRead(editionRegPath) If Err.Number <> 0 Then Err.Clear Continue For End If If Trim(CStr(editionValue)) <> EDITION_REQUIRED Then Continue For End If ' ----------------------------------------------------------------- ' NEW SECURITY HARDENING: ' Read uninstall string instead of blindly using registry key GUID ' Prevents malformed command execution ' ----------------------------------------------------------------- uninstallRegPath = "HKEY_LOCAL_MACHINE\" & _ KeyPath & "\" & Subkey & "\UninstallString" uninstallCmd = "" Err.Clear uninstallCmd = WshShell.RegRead(uninstallRegPath) If Err.Number <> 0 Then Err.Clear Continue For End If uninstallCmd = Trim(uninstallCmd) ' ----------------------------------------------------------------- ' NEW SECURITY HARDENING: ' Ensure uninstall string uses msiexec only ' Prevents arbitrary command execution ' ----------------------------------------------------------------- If LCase(Left(uninstallCmd, 7)) <> "msiexec" Then Continue For End If ' ----------------------------------------------------------------- ' NEW SECURITY HARDENING: ' Convert install command to silent uninstall safely ' ----------------------------------------------------------------- uninstallCmd = Replace(uninstallCmd, "/I", "/X", 1, -1, vbTextCompare) If InStr(1, uninstallCmd, "/qn", vbTextCompare) = 0 Then uninstallCmd = uninstallCmd & " /qn" End If ' ----------------------------------------------------------------- ' NEW SECURITY HARDENING: ' Run validated uninstall command only ' ----------------------------------------------------------------- returnValue = WshShell.Run(uninstallCmd, 0, True) End If Next End Function