Microsoft Windows Registry Guide, Second Edition
Choosing a Technique
Table 11-1 compares the scripting methods covered in this chapter. Each column represents one of the five scripting methods that I describe. For example, the Batch column describes using Reg.exe in a batch file. The MSI column describes Windows Installer package files that include registry settings. The similarities of all five methods are that they all enable you to change values as well as to add keys or values, and Windows supports all five methods without installing third-party tools or any resource kits.
Features | INF | REG | Batch | Script | MSI |
Difficulty | Medium | Low | Medium | High | Medium |
OS access | Basic | None | Full | Full | Basic |
Built-in support | Yes | Yes | Yes | Yes | Yes |
Change values | Yes | Yes | Yes | Yes | Yes |
Add keys/values | Yes | Yes | Yes | Yes | Yes |
Delete keys/values | Yes | Keys only | Yes | Yes | Yes |
Querying values | No | No | Yes | Yes | No |
Support for value types | High | Medium | Medium | Low | Medium |
Bitwise support | Yes | No | No | Yes | No |
I almost always prefer to write an INF file. You'll notice that most of the scripts in this book are INF files. I chose this method because I'm familiar with INF files, and they're easy to create and to read. I use scripts only when I have to query values from the registry. The advantage of using INF files is that they offer the flexibility to do anything that you want to do in the registry, but they don't require you to be a programmer. Choose whatever methods are most appropriate for you, but rely more heavily on INF files and scripts. You won't end up using just one of these techniques: you'll find that you'll use a combination of these methods, depending on the scenario. After you start using the scripting methods that I describe in this chapter, you'll master them in no time.
Now I'll describe the differences among these scripting methods. As the table shows, using REG files is the easiest method, and using scripts and Windows Installer package files is the most difficult. No matter which method you choose, they all become rather easy after you learn how to use them. Access to the operating system is important only if you're trying to do more than just edit the registry–for example, if you want to read values from the registry and then dump them to a text file. The most important difference to notice among these scripting methods is that only INF files and scripts provide high support for the many different types of values that you can store in the registry. The remaining methods support the basic value types, though, and that's often all you need. If you need to edit more esoteric types, you're better off writing an INF file or a script. INF files and scripts are also the only two methods that you can use to set and clear bits in values. For example, the bits in the value UserPreferencesMask indicate different user interface settings, and you enable or disable them by setting or clearing the corresponding bit. If this is your requirement, INF files or scripts are your best methods.