Click here for Table of Contents

Last Updated

Using Reg Files and Script Files

How to use and customise the registry, batch, and scripting files on Serenity's Web Site

Overview

Registry Files (Reg Files)

Batch Files (Bat Files)

Scripting Files

RegDelete.vbs

It is not possible to delete keys or values using reg files. This is a small vbs program that deletes keys or values from the registry.

[path] RegDelete [Key] | [Value]

PathPath to RegDelete (so Windows can find it). See the tip on the Windows 98 Tips and Hacks page to make Windows always find it.
NothingStarts RegDelete with a User Interface. Do not enclose keys or values in inverted commas when typing the key or value to delete.
KeyThe 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.
ValueThe 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	davidc@sia.net.au
'
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