PreventUninstallScript

 

Here is a repost of an old script of mine.
This helps prevent the uninstall of certain software through Control Panel

User the /Software switch to specify the software name.
/Remove:True will remove the block so you can uninstall it again.

 

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")
 
sMatch = WScript.Arguments.Named("Software")
bRemove = lcase(WScript.Arguments.Named("Remove"))
 
if sMatch = "" then  
    WScript.Echo "No Software Name set"
    WScript.quit(2000)
End If
 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ' Root level
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
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(lcase(sDisplayName), lcase(sMatch)) > 0 then        
            If bRemove = "true" Then
                oWsh.RegWrite "HKLM\" & strKeyPath & "\" & subkey & "\NoRemove", 0, "REG_DWORD"
                WScript.Echo "Protection for " & sDisplayName & " Removed"
            Else
                oWsh.RegWrite "HKLM\" & strKeyPath & "\" & subkey & "\NoRemove", 1, "REG_DWORD"
                WScript.Echo " Added Protection for " & sDisplayName
            End If            
        End If
    End If
Next
 
OsType = oWsh.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
 
If OsType = "AMD64" then
    strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ' Root level
    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
    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(lcase(sDisplayName), lcase(sMatch)) > 0 then
                If bRemove = "true" Then
                    oWsh.RegWrite "HKLM\" & strKeyPath & "\" & subkey & "\NoRemove", 0, "REG_DWORD"
                    WScript.Echo "Protection for " & sDisplayName & " Removed"
                Else
                    oWsh.RegWrite "HKLM\" & strKeyPath & "\" & subkey & "\NoRemove", 1, "REG_DWORD"
                    WScript.Echo " Added Protection for " & sDisplayName
                End If    
            End If                
        End If
    Next
End If