In this, the final part of my series on the Windows 9x Registry, we'll take a look at REG files, which let you automate and distribute updates and fixes to the Registry.
REG files are text files which contain a series of directives for editing the Registry. Using a REG file you can add a new Registry key or update or delete an existing value. And while there's no documented method for deleting Registry keys via a REG file, as you'll see later there is an undocumented method which will do the trick for you.
Exploring a REG file
An easy way to learn about REG files is to use the Registry's Export function to create one:
- Click Start -> Run, type regedit and click OK to open the Registry Editor.
- Navigate to the key:
HKEY_CURRENT_USER\Control Panel\Desktop.
- From the Registry Menu select Export Registry File.
- In the Export Registry File dialog box name the file desktop.reg, save it on the Desktop, make sure Selected Branch is selected in the Export Range section and click Save to create the file.
- Exit the Registry Editor, right-click desktop.reg and select Edit from the pop-up menu. You'll see something similar to Listing 1, although the exact contents depend on your Desktop configuration. (Note that Listing 1 has been truncated for space reasons.)
| Listing 1. A sample REG file |
|
REGEDIT4 [HKEY_CURRENT_USER\Control
Panel\Desktop] [HKEY_CURRENT_USER\Control
Panel\desktop\ResourceLocale] [HKEY_CURRENT_USER\Control
Panel\Desktop\WindowMetrics] |
While it's possible to create REG files entirely from scratch by writing your own, it's far easier to use this export method to create a REG file, make your modifications in Notepad or another text editor, and then write the updated data back to the Registry by double-clicking the edited REG file. This approach minimises typing errors and ensures consistency in key and value names.
REG file structure
Each REG files take the same form.
- It begins with the line:
REGEDIT4
indicating the REG file was created using version 4 of the Registry Editor (Windows XP uses version 5). This line is followed by a blank line.
- Next come separate sections for each Registry key to be added or edited. Each key's fully qualified pathname (that is, the entire name of the branch) is enclosed in square brackets. For example:
[HKEY_CURRENT_USER\Control Panel\Desktop]
- Under each key is an entry for each value you wish to add or change. Note, if you have used the Export method described above to create your REG file, you should delete lines referring to values or subkeys which you wish to leave unchanged, and limit the contents of your REG file to those items you wish to add or updated. Each value entry takes the form:
name=value
where name is the value name of the entry enclosed in quotation marks. There's one exception: If you are changing the default value for any key (those entries which are labelled Default in the Registry Editor) instead of using the value name you use @ without quotes, for example:
@="00000C09"
Value is the value to which you want to set the particular value name.
- Values take different forms depending on their data type. String data is enclosed in quotes. Here's an example:
"TileWallpaper"="0"
(Remember: String data can include numbers, spaces and some special characters as well as letters.) Binary data is a string of hexadecimal digits, separated by commas and preceded by the word hex:. For example:
"UserPreferencemask"=hex:be,00,00,00
DWORD data is a continuous string of hexadecimal digits preceded by the word dword:, thus:
"CaretWidth"=dword:00000001
Listing 2 shows another REG file example. Look closely and you'll notice one peculiarity: The file pathnames which appear include double backslashes instead of the usual single backslash:
@="C:\\WINDOWS\\NOTEPAD.EXE %1"
| Listing 2. A REG file containing file pathnames |
|
REGEDIT4 [HKEY_CLASSES_ROOT\txtfile\shell] [HKEY_CLASSES_ROOT\txtfile\shell\open] [HKEY_CLASSES_ROOT\txtfile\shell\open\command] [HKEY_CLASSES_ROOT\txtfile\shell\print] [HKEY_CLASSES_ROOT\txtfile\shell\print\command] |
That's because the backslash character is used to alert the Registry Editor that the next character in a string is a special character such as a carriage return, new line character or quotation mark. (Because strings are enclosed in quotes, there needs to be a way to indicate when the quotation mark is actually a part of the string, and not merely the closing quote to terminate the string.) Used in this way, the backslash is called an escape character. So, for example, to indicate a carriage return you use escape-r, which is written \r. To differentiate a backslash in a pathname from the escape character, you use escape-\, written \\.
Benefits of REG files
Why use REG files to update the Registry? The most important reason is REG files make it easy to install the same Registry update or fix on multiple computers. You write the REG file once, copy it onto each computer needing the fix (or distribute it via email), and then run the REG file – that is, double-click it – to install it on the computer. This is particularly useful for network administrators, but also handy for anyone wishing to share a Registry update. If you have inexperienced friends whose Registries need attention, creating a REG file you test on your own system first and then give to them is a great way to avoid problems. People also use this characteristic of REG files to share them on the Internet. Many Windows tweaking sites, for example, provide downloadable Registry 'hacks' in the form of REG files.
Editing a REG file is also a little safer than directly editing the Registry. Using a REG file, you can take your time to ensure everything is exactly as it should be before merging the changes into the Registry proper. When you're working in the Registry you don't have this luxury: Each change you make is immediately saved to the Registry.
| Geekgirl.tip: Shortcut Registry navigation |
|
You can zip straight to a subkey on an expanded Registry branch by typing the first letter or two of the subkey's name. For instance, to quickly jump to the txtfile subkey of HKEY_CLASSES_ROOT, expand HKEY_CLASSES_ROOT then type tx. Make sure you don't pause between typing the two letters, or you'll end up at the first subkey whose name begins with x. |
Dangers of REG files
Despite the benefits of using REG files, there are some real dangers. You need to exercise special caution when using REG files because, just as with direct editing of the Registry, any wrong move can render your computer unstable or even unusable. In particular, if you use a REG file created by someone else you must trust the source of the file completely. Running a REG file from an unknown or untrustworthy source on your computer is as perilous as using the Internet without anti-virus protection. Even if the REG file is not deliberately mischievous, it could be poorly designed or inappropriate for your computer system.
Compounding this danger is the fact that many Registry fixes are version-specific. While some REG files may be used on Windows 95, 98, Me, NT, 2000 and XP, many Registry settings and permissible values are limited to one or two operating systems. Thus a change which works in Windows Me may or may not work in Windows 98.
In practice, you'll find most Windows 98 tweaks work in Windows Me and vice versa, but the more disparate the operating systems, the greater the chance the tweak won't work. In addition, any REG file exported from a Windows XP or 2000 Registry will begin with the line:
Windows Registry Editor Version 5.00
Such files won't run at all on earlier versions of Windows unless you replace that first line with REGEDIT4. That's a useful hurdle, as in many cases Win XP/2000 Registry changes will not be appropriate for earlier systems.
Apart from the catastrophic changes a mischievous or incorrect REG file can wreak, some Registry changes will appear to have the desired effect, but may have serious side effects which don't become immediately apparent. By the time you do realise there's a problem, you may no longer remember the change you've made to the Registry (if you've deleted the REG file) or you may not even connect the new problems with the Registry changes you made earlier.
Try it out!
Try out a practical example for yourself. Take a look at this REG file:
REGEDIT4
[HKEY_CLASSES_ROOT\Folder\shell\dos]
@="&Go To DOS"[HKEY_CLASSES_ROOT\Folder\shell\dos\command]
@="command.com /k CD %1"
This tweak lets you right-click any folder and choose Go To DOS from the pop-up menu to open a DOS window in that folder. The REG file adds two keys to the Registry:
Folder\shell\dos
and its subkey:
Folder\shell\dos\command
within HKEY_CLASSES_ROOT.
The first key adds the option Go To DOS to the right-click menu of any folder. The ampersand (&) in the value is used to indicate the shortcut accelerator key to access this command, in this case the G key. If you'd wanted to use D as the accelerator key instead, the line would read:
@="Go to &DOS"
The second subkey does the actual work, defining the command to be executed when you select the Go To DOS option on the right-click menu:
- Command.com is the DOS Command Processor; so running Command.com gives you a DOS window.
- The /k switch essentially tells Windows to open the DOS window and stay there until told to exit.
- The CD %1 part of the command tells Windows to change directory to the selected folder (the %1 is a placeholder which is replaced by the full pathname of the selected folder).
To get the hang of using REG files, open Notepad and type in the lines above (or simply copy and paste them), save the file as Dosprompt.reg and then merge the REG file with your Registry. Then right-click any folder and choose Go To DOS from the pop-up menu to see the result.

To practice some more, try editing Dosprompt.reg and changing the accelerator key or the option's name on the pop-up menu. Then re-run the REG file and see the results. It's also worth opening the Registry using Regedit, navigating to HKEY_CLASSES_ROOT\Folder\shell and taking a look at the results of your handiwork up close.
An undocumented bonus
It's possible to delete individual values from the Registry using a little known technique. (Thanks to Microsoft MVP Alan Edwards for the tip.) All you need do is add a hyphen immediately after the Registry value, for example:
REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs]
"url3"=-
And while you won't find it in the documentation, there is a way to delete an entire Registry key and all its associated subkeys and values. To do so, preface the key name with a minus sign, thus:
REGEDIT4
[-HKEY_CLASSES_ROOT\keyname]
As you may guess, this is a particularly treacherous tool, making it incredibly easy to wipe out entire sections of your Registry – yet another reason to be wary of REG files you download from the Internet or obtain from doubtful sources.
If you'd like to try this out, here's a safe way to do so:
- Open the Registry using Regedit.
- Navigate to the key:
HKEY_CLASSES_ROOT\.txt
- From the Registry Menu select Export Registry File and export the selected branch to the file txtfile.reg.
- From the Registry Menu select Export Registry File and export the same branch to the file test.reg. You'll now have two copies of the branch's data contained in separate REG files.
- Close Regedit and edit the file test.reg. You'll see the text shown in Listing 3. Delete everything except the first two lines (three lines, if you count the blank line separating the two) and then edit the latter of these two lines by inserting a minus sign immediately after the opening square bracket, thus:
[-HKEY_CLASSES_ROOT\.txt]
- Close and save test.reg, then run it to merge it with the Registry.
- Use Regedit to open the Registry once more and you'll find the .txt subkey has gone from HKEY_CLASSES_ROOT.
- To resurrect the missing key, you can either use Regedit's Registry Menu -> Import Registry File option to import txtfile.reg, or you can simply run txtfile.reg to add the keys back into the Registry.
|
Listing 3. The contents of the .txt subkey exported into a REG file. |
|
REGEDIT4 [HKEY_CLASSES_ROOT\.txt] [HKEY_CLASSES_ROOT\.txt\ShellNew] [HKEY_CLASSES_ROOT\.txt\ShellEx] [HKEY_CLASSES_ROOT\.txt\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}] |
Step by step: Making REG files safer
Because REG files are so powerful it pays to be extremely cautious with them. One of the best safeguards is to change the action which occurs when you double-click a REG file.
- By default, double-clicking a REG file Merges the file into the Registry. You can tell this is the case by right-clicking any REG file and checking the command which appears in boldface type – that's the default. Although a prompt provides a warning when you are about to merge a REG file, it's all too easy to hit Enter before you realise what you've done.

- A neat way to make REG files a little less like a cracker with a short fuse is to change the default action from Merge to Edit. Then, when you double-click a REG file it will open in Notepad (or in WordPad, if it's too long for Notepad to handle). To do this, you'll need to do a spot of manual Registry editing. Start by opening the Registry Editor and navigating to the key:
HKEY_CLASSES_ROOT\regfile\shell
You'll find the current Default value is not set. When there's no default set, Windows assumes Open as the default double-click action. Just to confuse things, Open and Merge, in this case, are the same thing. Merge is merely the name for the command displayed on the pop-up menu, something you can check by clicking the Open subkey.

- To make Edit the default double-click action, select the \regfile\shell subkey once more and double-click its Default value in the right-hand pane to open an Edit String dialog box. Type edit in the Value Data box and click OK, then close the Registry Editor.
(Click to see a full-sized image.)
- To check the change has taken effect, right-click a REG file and check that Edit is now the bolded command in the pop-up menu. If it is, try double-clicking the REG file. It should open in Notepad or WordPad.

If you now want to Merge a REG file, you'll have to right-click the file and deliberately select Merge from the pop-up menu – a much safer method.
Of course, you could make this change via a REG file. If you want to use that method, your REG file should look like this:
REGEDIT4
[HKEY_CLASSES_ROOT\regfile\shell]
@="edit"Use Notepad to create the file, save it as safereg.reg, and then run it by double-clicking it. Once you've run it, of course, you will no longer be able to run REG files by double-clicking them.
Note: This technique works for any registered file type such as XLS, DOC, BAT, JPG files and so on. All you need to do is find the appropriate file definition subkey in HKEY_CLASSES_ROOT and change its shell subkey value to whichever default command you choose.
© 2003 Rose Vines
Support geekgirl'sDo you find the tutorials on this site useful? If so, please show your support by kicking in a few bucks to sponsor an orphanage for Afghan refugees. For a small amount, it is possible to make a difference in an area of the world which is hurting badly. |
|
|
| Want to know more? Read this post on my blog. |
| top | home | windows 9x menu |
