Section 8.6. Exporting and Importing Registry Data with Patches

8.6. Exporting and Importing Registry Data with Patches

Hives have an arcane format, making direct editing all but futile. Fortunately, the Registry Editor conveniently supports the importing and exporting of any number of keys and values with Registry patches . Patches ( .reg files) are ordinary ASCII text files that can contain anything from a single key to a dump of the entire Registry.

Registry patches can be created with Registry Editor or a standard text editor, such as Notepad. You can also use Notepad to view and modify patches, and then use Registry Editor to reimport the patch.

Patches have many practical uses, including creating local backups of portions of the Registry as a preventative measure before editing keys (see the previous section). You can create a Registry key on one computer and apply it on another, useful for migrating a single setting or a whole group of settings to any number of Windows systems. Patches can allow easier editing than with Registry Editor, and certainly afford quicker and more flexible searches.

To create a Registry patch, highlight the key you want to export and select File Export. Once you've chosen a filename, the selected key, any subkeys, and all their values and respective data will be saved in a single file with the .reg extension. In most cases, you wouldn't want to select My Computer to export the entire Registry, since, for no other reason, HKLM is enormous and you wouldn't want to reimport it in any case.

Before making any changes to a Registry key, do a quick backup by exporting the key. Depending on what changes you've made, the Registry might not be identical after reimporting the key, but at least you'll have a record of what the key looked like before the changes.


Importing .reg files isn't quite as simple as creating them, partly because of the concept of merging, and partly because of the potential for harm. It's important to note that the contents of a Registry patch are merged with existing keys; they don't simply overwrite them. So, if a given key contains four keys (apple, pear, banana, and peach), and you apply a Registry patch (pointing to the same key) that contains four keys (apple, pear, banana, and pomegranate), the resulting key will have five keys (apple, pear, banana , peach, and pomegranate). The existing values and keys will indeed be overwritten with those in the patch, but any additional values and keys in the Registry will remain intact.

Stop! Do Not Double-Click on This File!

The default action for double-clicking on a .reg file is not to edit the file, as you might expect, but to merge it into the Registry. Registry Editor does warn you before committing a patch, and then informs you that the patch was successful (both messages can be turned off with the /s command-line parametersee Appendix A). However, if you work with Registry patches often, and are concerned about accidentally applying one, you may want to change the default action so that .reg files are edited when double-clicked. Open the File Types dialog (Control Panel Folder Options File Types), highlight REGRegistration Entries in the list of file types, and click Advanced. Highlight the Edit action, click Set Default (making it appear bold), and click OK.


The format of .reg files is similar to .ini files, rather than anything resembling the way data is displayed in Registry Editor. A section begins with the full path of a key in square brackets, like this: [section name ] . This is followed by any number of values, each of the format name="data " (the default value appears as @="value "). Then, the next key (if any) is listed, followed by all the values it contains. The order of the keys, as well as the order of the values in each key, is irrelevant. However, if you were to move a key from one section to another, it would, in effect, be moving the value from one key to another.

The quotes around value data are only used for string values; binary values and REG_EXPAND_SZ values are prefixed with the keyword hex : and appear without quotes. Similarly, DWORD values are preceeded by dword : and appear without quotes. Any backslashes in value data (found most often in folder paths and Registry paths) are doubled to distinguish them from the backslashes in key names .

Lastly, the first line in every Registry patch created in Windows XP and Windows 2000 will be Windows Registry Editor Version 5.00 , followed by a blank line. Patches created in Windows 95, 98, and Me will instead begin with Registry Editor4 , also followed by a blank line. There doesn't appear to be any difference in the treatment of these two types of patches by Registry Editor.

Here is an excerpted Registry patch:

 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\mozilla.org\Mozilla 
 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\mozilla.org\Mozilla\0.9.2 (en)\Main] "Program Folder Path"="C:\\Documents and Settings\\All Users\\  Start Menu\\Programs\\Mozilla\\" "Install Directory"="C:\\Program Files\\Mozilla\\" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] "NoUpdateCheck"=dword:00000001 "Show_ChannelBand"="No" "Display Inline Images"="yes" "Show_ToolBar"="yes" "Check_Associations"="no" "SmoothScroll"=dword:00000001 "Play_Animations"="yes" "Play_Background_Sounds"="yes" "Display Inline Videos"="yes" "Print_Background"="no" 
.9.2 (en)\Main] "Program Folder Path"="C:\Documents and Settings\All Users\ Start Menu\Programs\Mozilla\" "Install Directory"="C:\Program Files\Mozilla\" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] "NoUpdateCheck"=dword:00000001 "Show_ChannelBand"="No" "Display Inline Images"="yes" "Show_ToolBar"="yes" "Check_Associations"="no" "SmoothScroll"=dword:00000001 "Play_Animations"="yes" "Play_Background_Sounds"="yes" "Display Inline Videos"="yes" "Print_Background"="no"

You may notice that these two keys are in different manufacturer branches, and wouldn't appear next to one another in the Registry. If you think about the way Registry patches are created, you'll realize that the one shown above couldn't have been created in a single step. Instead, two different Registry Patches were created, and the contents of one were cut and pasted into the other using a plain text editor. As long as you remove the redundant header, this is perfectly acceptable. In fact, it can be a very convenient way to implement several Registry changes in one step.

Extra credit question: given the structure of file types discussed earlier in this chapter, how would you create a single Registry patch that contains all the necessary information to register a new file association on any computer? Could you use such a patch to restore your preferred file type settings if another application were to ever overwrite them?



Windows XP in a Nutshell
Windows XP in a Nutshell, Second Edition
ISBN: 0596009003
EAN: 2147483647
Year: 2003
Pages: 266

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net