Windows XP Hacks, Second Edition
|
Hack 85. Safely Edit the Registry Using .reg FilesForgo the dangers and inconvenience of editing the Registry directly. Instead, use plain-text .reg files. When you're editing the Registry, it's easy to make small errors that cause major repercussions. You might inadvertently edit the wrong key, put in a wrong value, orgiven how confusing the Registry iseven make changes without realizing it. The Registry is unforgiving when this happens. It doesn't keep a backup, so you're stuck with the new setting unless you've made backups yourself [Hack #86] . When you edit the Registry directly, you're also apt to make errors if you're making multiple changes because you have no chance to look at all the changes you're making at once. There's a way to solve both problems: use .reg files to edit the Registry. These are plain ASCII text files you can create or read with Notepad or any text editor and merge into the Registry to make changes. You can create a .reg file from scratch, or you can export it from a portion of the Registry, edit it with Notepad or another text editor, and then merge it back into the Registry. You'll find that .reg files are particularly useful if you're going to make changes to the Registry of several computers or if you are leery about editing the Registry directly. You should also consider creating .reg files to copy the parts of the Registry you're about to edit using the Registry Editor [Hack #83] . Then, if you make a mistake with the Registry Editor, you can revert to the previous version of the Registry by merging the .reg file into the Registry. They're also useful if you need to do search-and-replace operations on parts of the Registry because the Registry Editor doesn't include search-and-replace functionality. You can do the search-and-replace operation in your text editor and then merge the edited file back into the Registry. To create a .reg file from an existing portion of the Registry, run the Registry Editor, highlight the key or portion of the Registry you want to export, and choose File Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Control Panel\Accessibility] [HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access] "On"="0" [HKEY_CURRENT_USER\Control Panel\Accessibility\HighContrast] "Flags"="126" "High Contrast Scheme"="High Contrast Black (large)" [HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Preference] "On"="0" [HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response] "AutoRepeatDelay"="1000" "AutoRepeatRate"="500" "BounceTime"="0" "DelayBeforeAcceptance"="1000" "Flags"="126" [HKEY_CURRENT_USER\Control Panel\Accessibility\MouseKeys] "Flags"="62" "MaximumSpeed"="80" "TimeToMaximumSpeed"="3000" [HKEY_CURRENT_USER\Control Panel\Accessibility\SerialKeys] [HKEY_CURRENT_USER\Control Panel\Accessibility\ShowSounds] "On"="0" [HKEY_CURRENT_USER\Control Panel\Accessibility\SoundSentry] "Flags"="2" "FSTextEffect"="0" "WindowsEffect"="1" [HKEY_CURRENT_USER\Control Panel\Accessibility\StickyKeys] "Flags"="510" [HKEY_CURRENT_USER\Control Panel\Accessibility\TimeOut] "Flags"="2" "TimeToWait"="300000" [HKEY_CURRENT_USER\Control Panel\Accessibility\ToggleKeys] "Flags"="62" Edit a .reg file as you would any other text file. As you can see, the first line of the .reg file starts with Windows Registry Editor Version 5.00. Don't change this; Windows XP uses it to confirm that the file does in fact contain Registry information. Previous versions of Windows have a different first line; for Windows 95/98/Me and Windows NT 4.0, the first line reads either REGEDIT4 or Registry Editor 4. The names of Registry subkeys are surrounded by brackets, and they include the full pathname to the subkey, such as [HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response] in our example. Following each subkey are the subkey values and data. Values and data are both surrounded by quotation marks. Here is the full section of a subkey, along with its associated values and data: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Mouclass] "ErrorControl"=dword:00000001 "Group"="Pointer Class" "Start"=dword:00000001 "Tag"=dword:00000001 "Type"=dword:00000001 "DisplayName"="Mouse Class Driver"
As you can see, quotes surround data for String values. DWORD values, however, are preceded by dword: and don't have quotes surrounding them. Similarly, binary values are preceded by hex: and don't have quotes surrounding them. Edit the value and data and save the file. When you've made your changes, import the file back into the Registry by choosing File
9.4.1. Delete Registry Keys and Values Using .reg Files
You can use a .reg file not just to create new keys or values or to modify existing ones, but also to delete keys and values. To delete a key with a .reg file, put a minus sign in front of the key name, inside the bracket, like this: [-HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
When you import the .reg file, that key will be deleted. Keep in mind that you won't be able to delete a key this way unless all its subkeys have been deleted first, so you'll have to delete them first. You can also delete a key's value using a .reg file, by putting a minus sign after the equals sign in a .reg file, like this: "BounceTime"=-
When you import this into the Registry, the value will be deleted but the key will still stay intact. 9.4.2. Protect the Registry by Changing the Default Action for Double-Clicking a .reg File
As mentioned earlier in this hack, when you double-click a .reg file, the file doesn't open for editing; instead, it gets merged directly into the Registry. This can easily cause serious problems because you might want to edit the file, and therefore end up double-clicking it, the way you normally open files in XP. But the file will end up merging it into the Registry and making Registry changes you didn't want to make. To solve the problem, you can change the default action so that a .reg file is opened for editing in Notepad rather than merged when you double-click it. In Windows Explorer, choose Tools 9.4.3. Change the Default Editor for .reg Files
Notepad is the default editor for editing .reg files, but if you have another text editor you'd rather use you can force that to be the default instead. First, follow the directions from the previous section to open the File Types dialog box and highlight the REG entry's Edit action. Then, click the Edit button and type in the full path and filename of the text editor you want to use to edit .reg files, followed by %1for example: C:\Program Files\TextPad 4\TextPad.exe %1 Then click OK twice.
|
|