Script to Delete registry entry based on Product name

Hi Experts,

I need help with creating a script that will delete a registry entry based on entry name. Reason, we are having issues installing adobe flash through SCCM. Researching the issue, we found that rouge entries of Adobe 11 under HKEY_CLASSES_ROOT\Installer\Products is the cause, if we delete those entries and then deploy the latest version it works perfect.

The problem is that under HKEY_CLASSES_ROOT\Installer\Products\ the next key varies based on the version of Adobe flash. So Adobe
(HKEY_CLASSES_ROOT\Installer\Products\A180D90768E45F34D976E6FA74EE85E5) could be version and then it changes based on older and newer versions of 11.

Instead of manually going through half of our organization, is there a script that will run and delete entries under HKEY_CLASSES_ROOT\Installer\Products with the name "Adobe Flash Player 11 " as that is listed as product name under the key.

Thanks in Advance for you help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This VBscript should do the work. Please note, it must be run at the highest admin privelege (not just as admin login, also elevated cmd pronpt)

' Constants (taken from WinReg.h)
Const HKEY_CLASSES_ROOT   = &H80000000
Const HKEY_CURRENT_USER   = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS          = &H80000003

Const REG_SZ        = 1
Const REG_BINARY    = 3
Const REG_DWORD     = 4
Const REG_MULTI_SZ  = 7

' Chose computer name, registry tree and key path
strComputer = "." ' Use . for current machine
strKeyPath = "Installer\Products"

' Connect to registry provider on target machine with current user
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

' Enum the subkeys of the key path we've chosen
oReg.EnumKey hDefKey, strKeyPath, arrSubKeys

For Each strSubkey In arrSubKeys
  strSubKeyPath = strKeyPath & "\" & strSubkey
  oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes

	 For i = LBound(arrValueNames) To UBound(arrValueNames)
	   strValueName = arrValueNames(i)
			if arrTypes(i) = REG_SZ then
						oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
						if ((strValueName = "ProductName") and (strValue = "Adobe Flash Player 11")) then
							msgbox "going to delete " & strSubKeyPath
							'Set objShell = Wscript.CreateObject("Wscript.Shell")
							DeleteSubkeys HKEY_CLASSES_ROOT, strSubKeyPath
						end if
			end if


Sub DeleteSubkeys(HKEY_CURRENT_USER, strKeyPath) 
    oReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys 

    If IsArray(arrSubkeys) Then 
        For Each strSubkey In arrSubkeys 
            DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & strSubkey 
    End If 

    oReg.DeleteKey HKEY_CURRENT_USER, strKeyPath 
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaya31Author Commented:
Hi Kimputer,

I tried to saved the script, renamed it vbs and vbsx and ran it through elevated cmd prompt and it doesn't deleted the key. Below is the exported registry key that points to what I want deleted, as mentioned, after under HCR\installer\products  that A180d... name changes based on versions. I'm not a scripting guy, maybe I left something out that is needed to delete or not running properly. Thanks again.

Windows Registry Editor Version 5.00

"ProductName"="Adobe Flash Player 11 Plugin"



To quote your original question:

"Adobe Flash Player 11 "

I even removed the trailing space to fix your error. But now you show me it should be:
"Adobe Flash Player 11 Plugin"

As programming is quite an exact science, if you give the wrong info, you will get a non-working script.

Use the original script, find:

if ((strValueName = "ProductName") and (strValue = "Adobe Flash Player 11")) then

Open in new window

Replace with:
if ((strValueName = "ProductName") and (strValue = "Adobe Flash Player 11 Plugin")) then

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

jaya31Author Commented:
Hi Kimputer,

This works great, thank much. Apologies, my mistake on the name.
 I just have one follow up question before closing. The subroutine at the bottom of the script refers to deleting keys from HKEY_CURRENT_USER. Again, not a programming\scripting person, just wanted to make sure there was nothing else happening.

I did run it on a test machine and worked deleting the key referring to Adobe, and didn't experience anything adverse. Thanks again.
The lower part is indeed a sub routine, and hence it's not really that key, but the key you input when you call the routine. It's indeed prone to misinterpretation, and I should have used a better variable name that would indicate it's a variable and not a fixed value.
jaya31Author Commented:
Thanks again, just wanted to make sure. Much appreciated, this is exactly what I needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.