/build/static/layout/Breadcrumb_cap_w.png

Need scribt to detect reg key/value and delete if present

OK, I did a search and found something similar but wasn't able to get it to do exactly what I wanted.
The Area of registry I'm looking at is:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlers\PlayCDAudioOnArrival
and the Values I'm looking for are:
iTunesPlaySongsOnArrival
iTunesShowSongsOnArrival
iTunesBurnCDOnArrival
iTunesImportSongsOnArrival

If and ONLY If any of them are present, I would like to delete them (the values or whatever you call them), but leave everything else normally found in the 'PlayCDAudioOnArrival' key

Also, there are subkeys in:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers\
such as: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers\iTunesImportSongsOnArrival
that I would like to also detect and get rid of the whole subkey (iTunesImportSongsOnArrival)

I tried this code, but it deletes the whole 'PlayCDAudioOnArrival" key. I also want to run the script silently without any popups.
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlers\PlayCDAudioOnArrival"
strValueName = "MSRipCDAudioOnArrival"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then
Wscript.Echo "The registry key does not exist."
Else
Wscript.Echo "The registry key exists."
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

End If

0 Comments   [ + ] Show comments

Answers (4)

Posted by: aogilmor 15 years ago
9th Degree Black Belt
0
you prolly wanna use the removeregistry table instead of a script if this is an msi installation.
Posted by: Thinkster 15 years ago
Yellow Belt
0
I'm not sure about a table, I just want to remove those particular registry keys/values, not the program..
Posted by: anonymous_9363 15 years ago
Red Belt
0
I tried this code, but it deletes the whole 'PlayCDAudioOnArrival" key.Well, it will do if you use the WMI registry provider object's 'DeleteKey' method! :) You want 'DeleteValue'. My advice would be to get hold of the cRegistry.VBS script from, IIRC, http://www.jsware.net. It's a neat encapsulation of the WMI registry provider object, with easy to use functions. It takes away a great deal of the pain associated with using this object. Plus, in contrast with 99% of code - particularly script - on the web, its code is an exercise in neat, concise and "it does exactly what it says on the tin" programming.

I also want to run the script silently without any popups.Either remove the WScript.Echo statements or, better, replace them with a call to a log file-writing function (of which there are a gazillion examples on the web). You might also write to the Event Log instead/as well.
Posted by: aogilmor 15 years ago
9th Degree Black Belt
0
Dude, did I say anything about removing a program?

Sigh.....

google removeregistry table site:microsoft.com

Anyway, if it's not part of a package, there are PLENTY of sample scripts to delete keys and subkeys and values (and suppress errors if they don't exist)

Sigh....

google scripting guys delete registry key and subkeys site:microsoft.com
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ