Windows Registry in VB.NET: Part 1

In this article I will explain you about the Windows Registry in VB.NET.
  • 1834

The Windows registry acts as a central repository of information for the operating system and the applications on a computer. This database is organized in a hierarchical format, based on a logical ordering of the elements stored within it. When storing information in the registry, select the appropriate location based on the type of information being stored. Be sure to avoid destroying information created by other applications because this can cause those applications to exhibit unexpected behavior and can adversely affect your own application.

Windows NT, 2000, and XP provide two versions of a Registry Editor: Regedt32.exe and Regedit.exe. Regedt32.exe is automatically installed in the %systemroot%\System32 folder. Regedit.exe is automatically installed in the %systemroot% folder. You can modify the registry using either of these Registry Editor utilities. However, if possible, you should use other utilities and tools provided with Windows 2000 to modify your system settings, such as those in the Control Panel. When you modify the registry with Registry Editor, the editor does not check for syntax or other errors. In addition, one modification to the registry may cause a cascade of changes throughout it. The results of an incorrect edit made with Registry Editor are unpredictable and may impair or disable the Windows 2000 operating system. However, by using other tools and utilities, you can ensure that modifications made to the registry are logical and valid, and you can manage any subsequent cascade of changes an edit may cause.

You can use Regedt32.exe in read-only mode (on the Options menu, click Read Only Mode) to safely view the registry and not inadvertently make changes. Switch off read-only mode when you are certain of the changes you wish to make.

Registry keys are the base unit of organization in the registry; they can be compared to folders in Windows Explorer. A particular key can have subkeys (just as a folder can have subfolders). Each key can also have multiple values associated with it, which are used to store information about your application. Each value holds one particular piece of information, which can be retrieved and updated when required. For instance, you can create a registry key for your company under the key HKEY_LOCAL_MACHINE\Software and then a subkey for each application that your company creates. Each subkey holds information specific to that application such as color settings, screen location, and product-specific file extensions.

The information stored in the registry is available to other applications and users, and therefore you should not use the registry to store security or critical application information. The main base Registry categories for the Microsoft operating systems are as follows:

  • CurrentUser. Stores information about user preferences.

  • LocalMachine. Stores configuration information for the local machine.

  • ClassesRoot. Stores information about types (and classes) and their properties.

  • Users. Stores information about the default user configuration.

  • PerformanceData. Stores performance information for software components.

  • CurrentConfig. Stores non-user-specific hardware information.

  • DynData. Stores dynamic data.

The Registry class has a static field corresponding to each of these key types. The Registry class members are described as follows:

  • ClassesRoot. Returns a RegistryKey type that provides access to the HKEY_CLASSES_ROOT key.

  • CurrentConfig. Returns a RegistryKey type that provides access to the HKEY_CURRENT_CONFIG key.

  • CurrentUser. Returns a RegistryKey type that provides access to the HKEY_CURRENT_USER key.

  • DynData. Returns a RegistryKey type that provides access to the HKEY_DYN_DATA key.

  • LocalMachine. Returns a RegistryKey type that provides access to the HKEY_LOCAL_MACHINE key.

  • PerformanceData. Returns a RegistryKey type that provides access to the HKEY_PERFORMANCE_DATA key.

  • Users. Returns a RegistryKey type that provides access to the HKEY_USERS key.

For example, if you want to access the HKEY_LOCAL_MACHINE key, you need to call the Registry.LocalMachine member that returns a RegistryKey instance pointing to the local machine key.   

Dim pRegKey As RegistryKey = Registry.LocalMachine

Conclusion

Hope this article would have helped you in understanding the Windows Registry in VB.NET. The second part of this article you will see in my next article.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.