Reg file to remove keys/values?

S

Steve Nielsen

What is the syntax for removing keys using a .reg file? Specifically, we
have a lab with several XP machines that have the problem of Disk
Cleanup hanging at Compress old files and the M$ fix is to edit the
registry to remove the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
Compress old files

It would be much easier (and safer) to have the lab operator merge a
..reg file than use regedit on each machine.

Thanks

Steve
 
D

David Candy

RegDelete.vbs
This is a small vbs program that deletes keys or values from the registry.

[path] RegDelete [Key] | [Value]

Path Path to RegDelete (so Windows can find it). See the tip on the Windows 98 Tips and Hacks page to make Windows always find it.
Nothing Starts RegDelete with a User Interface. Do not enclose keys or values in inverted commas when typing the key or value to delete.
Key The key to delete. Keys always end in a backslash. If the key contains a space it must be enclosed in inverted commas. Keys and sub-keys will be deleted.
Value The value to delete. Values do not have a trailing backslash. If the key contains a space it must be enclosed in inverted commas.

Copy the following lines into a new text document and save as RegDelete.vbs.

'RegDelete.vbs
'Deletes keys or values from the registry.
'
'Serenity Macros http://www.angelfire.com/biz/serenitymacros
'David Candy (e-mail address removed)
'
On Error Resume Next
vbPara=vbCRLF & vbCRLF
strExplain="RegDelete deletes keys and values from the registry." & vbPara & "Keys must end with a backspace and values must not." & vbPara & "Start without parameters to type in a key or value to delete, or place the key or value on the command line (use inverted commas to surround the key or value if it contains spaces)." & vbPara & "Continue"
strTitle="Reg Delete"
Key=""
Dim silent
Silent=""

Dim Sh
Set Sh = WScript.CreateObject("WScript.Shell")
ReportErrors "Creating Shell"

Key=GetKey()
If Key<>"" then
B=Sh.RegRead (Key)
If Err.Number=0 Then
Sh.RegDelete Key
If Err.Number =0 Then
If silent<>"yes" Then MsgBox Key & " deleted", vbOKOnly + vbInformation, strTitle
Else
ReportErrors "DeletingKey"
End If
Else
If Err.Number=-2147024893 then
Err.Clear
MsgBox Key & " didn't exist", vbOKOnly + vbCritical, strTitle
Else
ReportErrors "Reading before Deleting Key"
End If
End If
End If

ReportErrors "Main"
VisitSerenity

Function GetKey()
Dim Ag
Set Ag=Wscript.Arguments
ReportErrors "Creating Aguments"
If Ag.Count=1 then GetKey=Ag(0)
Silent="yes"
If Ag.Count >1 then sgBox "Too many parameters on command line. Try enclosing the key in a space",vbOKOnly + vbCritical, strTitle

If Ag.Count=0 then
If MsgBox (strExplain, vbYesNo + vbInformation, strTitle)=6 Then
GetKey=InputBox ("Enter the value or key to delete." & vbPara & "Keys must end in a backspace.", strTitle, strNamet1)
End If
End If
End Function

Sub ReportErrors(strModuleName)
If err.number<>0 then Msgbox "Error occured in " & strModuleName & " module of " & err.number& " - " & err.description & " type" , vbCritical + vbOKOnly, "Something unexpected"
Err.clear
End Sub

Sub VisitSerenity
Dim Ag
Set Ag=Wscript.Arguments
If Ag.Count<>1 then
If MsgBox("This program came from the Serenity Macros Web Site" & vbCRLF & vbCRLF & "Would you like to visit Serenity's Web Site now?", vbQuestion + vbYesNo + vbDefaultButton2, "Visit Serenity Macros") =6 Then
sh.Run "http:\\www.angelfire.com\biz\serenitymacros"
End If
End If
End Sub
Use this in a logon script.
 
A

Alex Nichol

Steve said:
What is the syntax for removing keys using a .reg file? Specifically, we
have a lab with several XP machines that have the problem of Disk
Cleanup hanging at Compress old files and the M$ fix is to edit the
registry to remove the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
Compress old files

It would be much easier (and safer) to have the lab operator merge a
.reg file than use regedit on each machine.

Export the key concerned (I would select the alternate file type of
Win9x/NT4 registration files' in the Save as dialog). Edit that with
Notepad. Put a - after the leading [ of any key you want to delete -
eg
[-HKEY_LOCAL_MACHINE\SOFTWARE\Unwanted]

and if you want, as I think here, to remove a value, leave the key and
set the name of the value to - as in for example
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches]
"Compress old files"=-

which removes that value from the key (leaving everything else in it)
 
D

David Candy

@=- for an unnamed value (called default in regedit)

--
----------------------------------------------------------
http://www.smh.com.au/yoursay/2004/06/11/index.html
Alex Nichol said:
Steve said:
What is the syntax for removing keys using a .reg file? Specifically, we
have a lab with several XP machines that have the problem of Disk
Cleanup hanging at Compress old files and the M$ fix is to edit the
registry to remove the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
Compress old files

It would be much easier (and safer) to have the lab operator merge a
.reg file than use regedit on each machine.

Export the key concerned (I would select the alternate file type of
Win9x/NT4 registration files' in the Save as dialog). Edit that with
Notepad. Put a - after the leading [ of any key you want to delete -
eg
[-HKEY_LOCAL_MACHINE\SOFTWARE\Unwanted]

and if you want, as I think here, to remove a value, leave the key and
set the name of the value to - as in for example
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches]
"Compress old files"=-

which removes that value from the key (leaving everything else in it)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top