Exporting Settings to Files

Exporting all or part of the registry is one of those things IT professionals and power users do often. By exporting, I mean copying portions of the registry to another file, typically a REG file but hive files are more useful. This is a great way to back up settings so you can easily restore them later, if necessary. It's also a good way to share settings with other users or computers. I often create REG files for settings I prefer so that I can change those settings simply by importing a REG file rather than clicking my way through the Windows XP user interface—one double-click replaces a hundred clicks.

In the IT world, exporting settings to REG files has practical purposes, too. First is deployment. REG files are the simplest and often the only way to deploy some settings with Windows XP. You can deploy REG files through your Windows XP answer file, for example, as you will learn in Chapter 12, "Deploying with Answer Files." It's also a convenient way to deploy settings from an intranet or helpdesk. Last, REG files are an easy way to add settings to your Office XP deployment. You can do this through the Office XP Resource Kit's Custom Installation Wizard. Chapter 14, "Deploying Office XP Settings," describes how to add REG files to Office XP's installation.

Regedit exports settings to four different types of files: registration, Win9x/NT4 registration, hive files, and text files. The differences between the four are significant, and you learn about them later in this chapter. Follow these steps to export branches of the registry to files:

  1. Click the key at the top of the branch you want to export.

  2. On the File menu, click Export to display the Export Registry File dialog box, shown in Figure 2-5.

    click to expand
    Figure 2-5: Make sure you choose which file format you want to use, regardless of the file extension you type in the File Name box.

  3. In the File Name box, enter a name for the file you're creating.

  4. Select the option for the export range you want:

    • To back up the entire registry, select the All option.

    • To back up the selected branch, select the Selected Branch option.

  5. In the Save As Type list, click the type of file you want to create: Registration Files (*.reg), Registry Hive Files (*.*), Text Files (*.txt), or Win9x/NT4 Registration Files (*.reg).

  6. Click Save.

Importing a file into the registry is similar to opening a file. Click File, Import; in the Files Of Type list, click the type of file that you're importing; then, in the File Name box, type the path and name of the file you're importing. The following sections describe each of the file types that you see in the Save As Type and Files Of Type lists. Each type is a different file format and thus suited to different purposes than the other types.

Registration Files

Registration files are version 5 REG files—plain text files that look similar to INI flies. Each section name represents a key, and each item in a section represents a value. The following listing is a sample of a version 5 REG file:

Listing 2-2: Sample Version 5 REG File

start example

 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Sample] "String"="Jerry Honeycutt" "Binary"=hex:01,02,03,04,05,06,07,08 "DWORD"=dword:00004377 "Expandable String"=hex(2):25,00,55,00,53,00,45,00,52,00,00,00 "MultiString"=hex(7):48,00,65,00,6c,00,6c,00,6f,00,00,00,00 [HKEY_CURRENT_USER\Sample\Subkey] 

end example

The most important thing to know about version 5 REG files is that they are Unicode, and some programs can't handle Unicode REG files properly. And because these files are Unicode, each character in REG_EXPAND_SZ and REG_MULTI_SZ values is two bytes wide. In the listing just shown, you'll notice this in the values called Expandable String and MultiString. For example, the letter A is 0x0041, not 0x41. For more information about Unicode-encoded text, see Chapter 1, "Learning the Basics." Windows 2000 and Windows XP are the only Microsoft operating systems that support version 5 REG files.

In the previous section, you learned how to import REG files using Regedit. You can also double-click a REG file to merge it into the registry. Regedit will prompt to merge the settings that the file contains into the registry and, after you click Yes, it will tell you when it's finished. If you're deploying a REG file to users, however, you don't want them to see the message or answer the prompt, so you'll use Regedit's /s command-line option to run it quietly. For example:

 regedit settings.reg /s 

Use this command line from batch files, scripts, answer files, or even from the Office XP Resource Kit's Custom Installation Wizard. For more information about creating and deploying REG files, see the following chapters:

  • Chapter 9, "Scripting Registry Changes," describes the format of each value type in REG files and shows you how to build them manually.

  • Chapter 12, "Deploying with Answer Files," describes how to deploy REG files as part of your Windows XP answer file—a great way to deploy user settings.

  • Chapter 14, "Deploying Office XP Settings," describes how to deploy REG files as part of your Office XP customizations.

Caution 

Don't import a REG file that you create in one version of Windows into another version—at least not without thinking about it carefully. For example, exporting hardware settings from the Windows NT 4.0 registry and importing them into the Windows XP registry will likely wreak havoc with Windows XP. Some settings are fine to share across Windows versions, however, such as file associations in HKCR and some programs' settings. Use common sense.

Win9x/NT4 Registration Files

Win9x/NT4 registration files are version 4 REG files, which Windows 95, Windows 98, Windows Me, and Windows NT 4.0 support. The following sample is a version 4 ANSI REG file. The settings are the same as the version 5 Unicode REG file you saw in the previous section:

Listing 2-3: Sample Version 4 REG File

start example

 REGEDIT4 [HKEY_CURRENT_USER\Sample] "String"="Jerry Honeycutt" "Binary"=hex:01,02,03,04,05,06,07,08 "DWORD"=dword:00004377 "Expandable String"=hex(2):25,55,53,45,52,00 "MultiString"=hex(7):48,65,6c,6c,6f,00,00 [HKEY_CURRENT_USER\Sample\Subkey] 

end example

Instead of Unicode text, version 4 files are ANSI text files. That means that each character is a single byte wide. The letter A is 0x41. You notice the difference between this and the earlier Unicode REG file in the Expandable String and MultiString values. Characters in REG_EXPAND_SZ and REG_MULTI_SZ values are single bytes, which is more natural for most folks. This is the file format that's compatible with programs expecting ANSI REG files, and it has the added benefit of being compatible with earlier versions of Regedit.

start sidebar
Choosing Between REG and Hive Files

Registry Editor exports branches to four different file formats. Each format has strengths and weaknesses that make it appropriate for some tasks and useless for others. This section should help you choose the right format each time.

Exporting to hive files is my choice most of the time. The reason I like hive files so much is because they're much more accurate than either type of REG file. They are the same format as the Windows XP working hive files, so they represent settings exactly the same way. Also, when you import a hive file, Registry Editor deletes the branch it's replacing before importing the settings. In other words, the editor removes any settings that exist in the working registry but not in the hive file you're importing. When restoring keys from a backup after an unsuccessful registry edit, this is exactly the behavior you want. Hive files have one more strength that make them my choice most of the time: You can load them as new hives and view their contents without affecting other parts of the registry. Their only drawback is you can't view them in Notepad.

Although hive files are my choice most of the time, there are a few scenarios that require me to use REG files. First is when I'm working with programs that don't understand hive files. For example, the Office XP Resource Kit's Custom Installation Wizard can read REG files but not hive files. Second is when I'm exporting settings to different versions of Windows. Windows 98 doesn't provide a way to load hive files. Last, and important in my view, is when I'm trying to track down a setting in the registry by comparing snapshots. Comparing two hive files isn't feasible, but comparing two REG files is easy using Microsoft Word 2002.

end sidebar

Hive Files

Hive files are binary files that contain portions of the registry. As you recall from Chapter 1, "Learning the Basics," Windows XP stores different parts of the registry in different hive files. Regedit displays all these hives together in one logical unit. Hive files are useful tools, though. You can export branches to hive files that can then be imported to another computer or by another user. They're great backups.

Exported hive files have purposes similar to REG files. Hive files have most of the advantages of REG files, except that you can't view and edit them in a text editor. The advantage that hive files have over REG files is that you can load and edit them in Regedit without actually replacing your own settings. The section "Working with Hive Files," on the facing page, describes how to load hive files.

Text Files

You can export keys to text files, but you can't import them back into the registry. If you're curious what an exported text file looks like, take a look at the sample printer output in the "Printing the Registry" section. They are one and the same. Regedit makes exported text files more readable than REG files, which can help you interpret settings better, but that's about the only use of text files.



Microsoft Windows XP Registry Guide
Microsoft Windows XP Registry Guide (Bpg-Other)
ISBN: 0735617880
EAN: 2147483647
Year: 2005
Pages: 185

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