The central importance of the registry in the Windows server environment demands some kind of command-line control of registry settings. The Microsoft Windows NT Resource Kit has offered Reginfo as far back as NT 3.5 or NT 3.1, but Windows 2000 and later come with a useful and—at least in my experience—more reliable tool in reg.exe. Unlike Reginfo, the Reg command is built into the OS, so you don't need to install it.

Several Reg options are available. The Query option lets you perform searches, the Add option lets you add or change keys and values, and the Delete option lets you delete values or keys. You can use the Save and Restore options to back up and restore pieces of the registry to hive files. The Copy option lets you copy entire chunks of a remote system's registry to your computer's registry. And, finally, the Export and Import options let you export and import pieces of the registry to or from Unicode text files.

A comprehensive explanation of Reg's syntax would require more space than I have, so instead I offer some sample scenarios that illustrate Reg's usefulness. To use Reg, you must have the correct permissions; typically (but not always), you need to be an administrator. The ACL of the registry component you want to modify decides whether you can run a given Reg command. Also, Reg isn't case sensitive, except when you're feeding the registry data—some registry subkeys are case sensitive, so be sure to type data values as the registry requires.

Most commonly, I use Reg to change an existing registry value or to add a new value. For example, suppose I want to add to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters subkey a value called CrashOnCtrlScroll (of type REG_DWORD) that's set to 1. This value would let me use the Ctrl+Scroll Lock key combination to force a blue screen on my system—a useful capability for determining the causes of lockups. The entry doesn't exist by default on Windows Server 2003, Windows XP, or Win2K systems, so I need to use Reg to create the entry and give it a value of 1:

reg add HKLM\SYSTEMCurrentControlSet\Services\i8042prt
\Parameters /v CrashOnCntrlScroll /t REG_DWORD /d 1 /f

The first part of the command points to the registry key I want to modify. Notice that Reg accepts the shorthand HKLM instead of HKEY_LOCAL_MACHINE. The /v parameter followed by CrashOnCtrlScroll tells Reg to create or modify the value entry by that name. The /t parameter determines the type of value entry, the /d 1 parameter tells Reg to fill the subkey with a value of 1, and the /f parameter tells Reg to overwrite the value if necessary. (Without this final parameter, if a CrashOnCtrlScroll entry exists, Reg will stop and ask "Are you sure?") Now, I can place this command line inside a batch file, then run that batch file on any system to enable the forced­blue screen key sequence.

Here's another scenario in which Reg proves useful. When you open a shared folder in Windows 2003, XP, or Win2K, you might notice that Windows Explorer displays its flashlight icon while it seems to search for something. Even if the share contains only a few files, Windows Explorer searches the folder for Scheduled Tasks. To instruct Windows Explorer not to perform this search, you can use Reg to delete the entire HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RemoteComputer\Namespace\{D6277990-4C6A-11CF-8D87-00AA0060F5BF} registry subkey:

reg delete HKLM\SOFTWARE\Microsoft\Windows
\CurrentVersion\Explorer\RemoteComputer\Namespace
\{D6277990-4C6A-11CF-8D87-00AA0060F5BF} /f

The syntax for this command is simple to follow. Only two parameters follow Reg Delete: the name of the key you want to delete and the /f option. You don't need to reboot to effect this deletion.

The prospect of deleting a registry subkey might concern you. You might wonder how you would restore the key, should you decide you need it. To avoid this dilemma, you can use Reg's Export option to export the subkey before you delete it:

reg export HKLM\SOFTWARE\Microsoft\Windows
\CurrentVersion\Explorer\RemoteComputer\Namespace
\{D6277990-4C6A-11CF-8D87-00AA0060F5BF} backup.reg

This command exports the key in Unicode format and creates a familiar .reg file, which you've probably seen Regedit create. To import the file later, you simply use the Reg Import command, followed by the same information—remember to add the /f parameter to prevent Reg from asking you for confirmation.

These scenarios represent only a sampling of what Reg can do. Take your favorite Reg commands and make batch files of them. Then, when trouble calls, you can have a CD-ROM full of batch files at the ready.

End of Article




You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

After reading this article I was quite excited to try the reg.exe utility. I tried both on Win2K Advanced Server and Win2K Professional, but neither had this utility. I searched my entire PC for the reg.exe and reg.* and found nothing. On my laptop (Windows XP Pro) I had no problem, but would like to use this on my server. What am I doing wrong...is this a utility that must be installed. In the article it states that it comes built in to the OS, but is it an optional part of the OS?

Wilson Steiger

For Windows 2000, reg.exe only comes with the Resource Kit, I believe; for Windows XP, it's built in.

Robert Morley

I've found the REGINI.EXE tool from the Windows 2000 Server resource kit far more powerful. In addition to doing everything that REG.EXE can do, REGINI.exe can also change permissions on registry keys. Useful if, say, you want to allow everyone to update HKLM\CLSID\FormFlow.Form (this, with other registry permissions changed, stops an annoying popup for non-administrators on Windows 2000/XP when they try FormFlow).

Chris Keene

What are the alternatives on other OS's?

msteudel

Article Rating 2 out of 5

Most other OSes do not have anything like the registry, which is basically an OS internals obfuscation mechanism.

Some folks say the registry obscures the details of OS configuration on purpose, to lock out other vendors; some say that the windows OS is so grossly inefficient it must have a pre-digested binary configuration in order to achieve reasonable interface response.

Other OSes have configuration interfaces that are human-readable, rather than binary blobs... for example, in unix-derived systems there are configuration directories containing configuration files; they correspond to hives and keys but can be manipulated with simple text editor (and more importantly, they can be COMMENTED for human comprehension).

Compaq/DEC VMS and IBM's OS390/MVS and OS/400 systems also use human-readable configuration systems.

Most people outside the windows hothouse consider the registry to be an abomination.

Anonymous User

reg is known as regedit on win2k

Anonymous User

Article Rating 4 out of 5

Excelent Tutorial, it was pretty useful, thanks a lot

Anonymous User

Article Rating 5 out of 5

 
 

ADS BY GOOGLE