Many will be familiar with the graphical interface tool regedit.exe that is available for editing the Windows Registry. Less familiar, however, is the command-line utility reg.exe that also comes with Windows. This accessory will do anything that regedit.exe can do and has the additional facility of being directly usable in scripts. It is a common tool for system administrators with many computers to manage but can also be useful to the more experienced home PC user. I will discuss some aspects that may be of interest to this latter group. More details can be found at this Microsoft site.
Registry editing is not for everybody but it is not as fearsome an operation as it is sometimes made out to be. Just be sure to follow the iron-clad rule to back up the Registry first before editing. There are many useful tweaks that involve a simple Registry edit and reg.exe provides a way that is simpler and safer in some ways than Regedit. It also provides a way to back up keys or entire hives of the Registry into files that can be stored off the main drive.
Like some other command-line utilities, the reg command is a shell or console that has its own set of sub-commands. A complete command will consist of
reg subcommand variables Table I lists these subcommands and some are discussed in more detail in
sections that follow. The commands can be carried out on remote networked computers as well as the local computer but I will confine the discussion to operations involving just the local computer.
This command is used to add keys and values to the Registry. The syntax is given by
REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f] Table II explains the entries.
REG ADD provides a quick and simple method for adding new keys to the Registry or modifying old ones. As an example, let's look at how to add the sub- key "HackersAreUs" to the Local Machine Software key. The command would be
HKLM\Software\HackersAreUs Now let's add a value named "Stuff" and make it a binary entry with data "0001". The command would be
REG ADD HKLM\Software\HackersAreUs /v Stuff /t REG_BINARY /d 0001 The
two commands could have been executed as a single command but I have split them to make the process clearer. I have used upper case for REG ADD but that is for clarity and is not required.
Keys and values can be deleted in a similar but somewhat simpler fashion. The syntax is
REG DELETE KeyName [/v ValueName | /ve | /va] [/f] Table III describes the parameters.
Backing up and restoring the RegistryProviding methods for backing up and restoring the Registry are some of the most important applications for
Saving and restoring hive filesTo create a binary backup, use the command
REG SAVE KeyName FileName
REG RESTORE KeyName FileName
Exporting and importing REG filesREG files are specially formatted text files with the extension "reg" that are copies of one or more Registry keys. They are often encountered as a way to carry out small Registry edits or in using Regedit.. They can also be used for backup. The commands are
REG EXPORT KeyName FileName
REG IMPORT FileName
If you want to take a quick look at what is contained in a particular Registry key or in a particular value, you can use the command
REG QUERY KeyName [/v ValueName | /ve] [/s] The only new parameter here is /s. This switch will cause all the subkeys and values in a key to be queried.