5.6 Saving and Loading Registry KeysRegEdt32 allows you to dump Registry data into ordinary files that you can back up or use on other machines. You can save data in binary and text formats, and you can reload binary data when you need it again. The text format has the advantage of being human-readable, but the binary format is more efficient and is the only one RegEdt32 can import. (For more details on using this capability to back up your Registry, see Chapter 3.) RegEdt32 normally deals with the hive files stored in %systemroot%\system32\Config. However, you can also create your own files that contain just the keys and values you want. Once you've created such a file, you can load it back to its original location or anywhere else in the Registry. You can also use the file on another machine's Registry. 5.6.1 Saving KeysTo create a binary file of Registry data, just select the key or subkey you want to save, then use RegEdt32's RegistrySave Key command. When the standard Save dialog appears, specify a filename, and RegEdt32 stores the selected key's contents (as well as those of its subkeys) to the file (as long as you have adequate permission to read the key, its subkeys, and their values). The completed file is an ordinary file, so you can copy it to floppy, email it, or handle it just like any other kind of document. There's no way to combine more than one key in a file unless they have a common parent. If you want to capture web browser settings from your local machine, you could save HKLM\Software\Microsoft and HKLM\Software\Netscape in two separate files, or you could save HKLM\Software and get them both--plus a lot of other unrelated stuff. 5.6.2 Restoring KeysOnce you've saved a key, restoring it is fairly straightforward. Select the location where you want the key to appear when loaded, then use the RegistryRestore Key... command. RegEdt32 loads the saved key as a subkey of the currently selected key. For example, if you select HKLM\Software\Qualcomm\Eudora and load a file, the saved file's contents appear under Eudora. Be careful with this command; the saved key file doesn't contain any information about the key's path, so RegEdt32 can't warn you that you're restoring a key in the wrong place. When the new key is loaded, it actually replaces allsubkeys and values of the selected key. Before anything actually gets replaced, you'll see a warning dialog asking you to confirm that you want to wipe out all the existing subkeys and values of the selected key. Unfortunately, though, the dialog doesn't tell you which key is about to be affected, so make sure you double-check the selected key to ensure it's the one you meant to restore over. 5.6.3 Loading Saved Keys as HivesWhen you load a key with RegistryRestore Key..., it overwrites whatever was there before. You can also load a saved key as a new hive without overwriting any existing data. When you do this, the loaded key is mapped into the Registry the same way the standard system hives are, and it remains loaded until you manually unload it. This function gives you an easy way to add a copy of a user account, since you can just grab HKU\sid from one machine and load it as a hive under HKU on another. You may load a saved key as a hive under HKU or HKLM but not any other root key. If you have HKU or HKLM selected, RegEdt32 enables the RegistryLoad Hive... command; it is disabled otherwise. (It'll also be disabled if you have read-only mode enabled.) When you load a key as a hive with this command, the saved key is loaded as a subkey of whichever root you loaded it into. You have to name the new key after you select the file to be loaded; this name is used to identify the new hive. For example, if you select HKU and load a saved key, telling RegEdt32 to namethe new key ExplodingStuff, the new hive appears as HKU\ExplodingStuff. Once a saved key is loaded as a hive, you can modify its keys and values like any other key. The changes are reflected in the saved key file, which remains loaded and available until you explicitly unload it with the RegistryUnload Hive command. 5.6.4 Saving as TextRegEdt32 also allows you to save a key and its values to a text file with the RegistrySave Subtree As... command. The formatting is identical to what appears when you print a key. If you need to search the Registry for a particular value (as opposed to a key name, which RegEdt32 can do) your options are to use RegEdit or to save the root key you want to search to a text file and search it yourself. Apart from that, this command isn't very useful. 5.6.5 Providing an Improvised ClipboardThere's one major feature that RegEdt32 and RegEdit both lack: a real set of Clipboard operations. It would really be handy to be able to copy a Registry key from one location and paste it in another, especially since both programs let you open the Registries of other machines on the network. While RegEdt32 doesn't directly provide Clipboard support, you can get the same effect with the RegistrySave Key... and RegistryRestore Key... commands. Let's say you're setting up a batch of new laptop machines running Windows 2000 Professional for your company's sales force. They're all on the network, but you want to set up each laptop's Dial-Up Networking (DUN) phonebook entries so that they're all the same. Here's one way to accomplish your goal:
5.6.6 A True StoryNow it's time for an anecdote. While writing this chapter, I ran into a problem. The shareware screen capture software I use to grab figures for my writing (the excellent SnagIt/32 from TechSmith; http://www.techsmith.com/) is installed under my account on a machine named enigma. When I'm logged on to that machine, SnagIt can find its registration key and settings data in HKCU\Software\TechSmith\SnagIt\Settings, and it's happy. However, for some of the figures, I needed to log into a different domain, and since I wasn't logged in as the same user, SnagIt could no longer see its settings data. To make things worse, I couldn't find the piece of paper with my registration code, and I was in a hurry. Solution: use RegEdt32. I logged onto enigma, saved the SnagIt settings key by selecting HKCU\Software\TechSmith\SnagIt\Settings and using the RegistrySave Key command, and logged out. I then logged into my domain account, selected HKCU\Software\TechSmith\SnagIt, used the RegistryRestore Key command to restore the file I just saved, and ran SnagIt again. Problem solved! A few minutes later, I captured all the necessary images and was back on schedule. |