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
3 Comments
Thank you very much Jake. Just what I need m
This is a great idea!
I tried it out, however Windows allowed me to uninstall the software I had specified in the Command Line.
Is there any limitations to the software this might prevent being uninstalled?
Hey Ben,
The first thing would be to check that the registry entry is actually being created.
Also, the difference between 32bit and 64bit software may mean that the registry entry could be in a different location.
Admittedly this script is flawed in this way, but could be easily adapted to search all locations.
Leave A Comment