Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

December 30, 2003 12:00 AM

Integral Reg

Command-line registry power at your fingertips
Windows IT Pro
InstantDoc ID #41109
Rating: (3)

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.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    May 05, 2005

    Excelent Tutorial, it was pretty useful, thanks a lot

  • Anonymous User
    7 years ago
    Apr 18, 2005

    reg is known as regedit on win2k

  • Anonymous User
    7 years ago
    Feb 25, 2005

    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.

  • MARK
    7 years ago
    Feb 02, 2005

    What are the alternatives on other OS's?

  • Chris Keene
    8 years ago
    Jul 02, 2004

    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).

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.