Reader to Reader: Workaround for New Default Behavior in Win2K’s Regedit


\[Editor's Note: Email your scripting solutions (400 words or less) to Reader to Reader at [email protected] Please include your script and phone number. We edit submissions for style, grammar, and length. If we print your contribution, you receive $100.\]

In Windows 2000, regedit opens from the last subkey you had opened in the previous session. Many people might find this new default behavior annoying because this process can take a while to finish, especially if your last subkey was deep (i.e., three or more levels) within the registry. The registry editor's UI doesn't provide a way to disable this default behavior, but I've developed a workaround.

Regedit maintains the last opened key under the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey subkey. Every time you exit the registry editor, the system automatically updates this subkey. Although you can change this default behavior by disabling write permissions for the LastKey subkey, you can change permissions only in regedt32. Thus, you would have to always use the more specialized regedt32 and not the simpler regedit to work in the registry.

A better solution is to use the workaround code in Listing 1. As callout A in Listing 1 shows, the workaround uses the WshShell object's RegWrite method to set regedit's LastKey subkey value to an empty string. Then, the workaround launches regedit. When the registry editor starts up, it looks in the LastKey subkey and finds an empty value, which prompts it to use the registry's root path. Thus, regedit opens with the main window displayed.

The code works with any version of Windows Script Host (WSH) on your Win2K machine. (The code won't work on a Windows NT machine because only Win2K's regedit supports LastKey.) To use the workaround, save the code in Listing 1 in a .vbs file (e.g., RunRegedit.vbs) and place the file on your desktop. When you want to launch regedit, just double-click it instead of the regular regedit desktop icon that you might have. If you routinely work in a specific subtree or key, you can replace the empty string ("") in the code at callout A with that subtree's path (e.g., "HKLM\SOFTWARE"). That way, when you click the .vbs file on your desktop, the registry editor opens, displaying the subtree in which you want to work, but won't take a long time to open.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.