1. Home
  2. Computing & Technology
  3. Visual Basic

Programming the Registry using VB 6 and VB.NET
Learn what it's for and how to use it in VB programs!

By , About.com Guide

Jul 7 2007

About The Registry

Before .NET, Microsoft's COM dumped references to shared components into the catchall Windows warehouse, the System directory, and then "registered" them in Windows so other programs could locate them. (This was a big step up from DOS where programs had to be found by searching every directory in the "path" or using a directory location stored in a configuration or "INI" file!) This is one reason why the registry is such a critical and sensitive part of Windows. Without it, one piece of software can't locate another one.

Since the registry is extremely sensitive and critical, this is a good time to repeat the standard advice seen in every piece of Microsoft documentation:

Make sure to back up the registry before you modify it. Make sure that you know how to restore the registry if a problem occurs.

For information about how to do that, see this Microsoft article, How to back up, edit, and restore the registry in Windows XP and Windows Server 2003.

.NET doesn't use the registry to identify program components anymore. In .NET, every assembly (the files that a .NET application is made of) starts with a data store called the manifest that takes the place of the information that was formerly saved in the registry. The manifest contains metadata (data about data) telling the Common Language Runtime (CLR) what it needs to know to execute the assembly instructions.

The registry is still a very important part of Windows and .NET. Partly because there is still a lot of COM programming that may last into the next century. And partly because there is a lot of other information stored in the registry too. Microsoft has stated that their ongoing design goal is to move away from the registry. My advice is, "Don't hold your breath waiting for it to happen."

The Microsoft Computer Dictionary, Fifth Edition, defines the registry as:

"A central hierarchical database used in Microsoft Windows ... to store information necessary to configure the system ..."

"The Registry contains information that Windows continually references during operation, such as profiles for each user, the applications installed on the computer and the types of documents that each can create, property sheet settings for folders and application icons, what hardware exists on the system, and the ports that are being used."

The registry has a reputation of being totally mysterious and very complex. There's some justification for that, but the overall concept is really pretty simple. It's just a tree-structured database with (for Windows XP) five main nodes:

  • HKEY_CLASSES_ROOT - file associations and COM objects.
  • HKEY_CURRENT_USER - the current user's configuration settings.
  • HKEY_LOCAL_MACHINE - local system configuration settings.
  • HKEY_USERS - settings for the default and other users.
  • HKEY_CURRENT_CONFIG - the current system's hardware and software configuration.

You can update the registry manually using the Windows Regedit utility. (Regedt32 is used with Windows NT 4.0 and Windows 2000. In Windows XP and Windows Server 2003, they're the same because Regedt32 simply calls Regedit.)

Two trends that are changing the registry right now are:

  • 64-Bit versions of Windows
  • Virtualization of the Registry in Windows Vista

64-bit versions of Windows have both 32-bit and 64-bit registry keys and many keys have both 32-bit and 64-bit keys with the same name. To keep things straight, 64-bit versions save the 32-bit keys in the node: HKEY_LOCAL_MACHINE\Software\WOW6432.

A lot of the changes in Windows Vista are designed to simply make the system more secure and registry virtualization is one of those. The original idea behind the registry was to make a global datastore for all applications to enhance speed and flexibility. Today, security concerns override and a single place where malware can attack the whole machine is not considered to be such a great idea anymore. In Windows Vista, applications running under a standard account (not an administrative account) that need to write to a global registry key (such as HKEY_LOCAL_MACHINE) will be silently and automatically redirected to a "per-user" key (such as HKEY_USERS\<User SID>_Classes\VirtualStore\Machine\). Microsoft claims this is a temporary solution, however, and warns us not to depend on it in future operating systems.

Windows Vista throws all kinds of roadblocks into registry editing, but this is a programming article (and not one on Vista systems administration) so I think I better get back on my original message. (This article was written with and for Windows XP.)

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. Programming the Registry using VB 6 and VB.NET

©2009 About.com, a part of The New York Times Company.

All rights reserved.