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.
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)
Please log in to answer
Posted by:
aogilmor
15 years ago
Posted by:
Thinkster
15 years ago
Posted by:
anonymous_9363
15 years ago
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
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
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.
so that the conversation will remain readable.