Structure of Windows Registry

By Pritam
Feb 7th, 2012
Structure of Windows RegistryWindows Registry is nothing but acentral storehouse for all settings for the Windows operating systems. This includes hardware configuration,file associations, and control panel settings
Manyother programs also store their settings in the windows registry. 
This articlewill take you from basics of WindowsRegistry to some of its advanced concepts. Enjoy the read!!

Technically, Windows Registry is ahierarchical database that stores configuration settings and options onMicrosoft Windows operating systems. It contains settings for low-leveloperating system components as well as the applications running on theplatform: the kernel, device drivers, services, SAM, user interface and thirdparty applications all make use of the registry. The registry also provides ameans to access counters for profiling system performance.

Let’s see how these registries are structured inOS:

TheWindows Registry is organized much like the Windows file system that isvisible in Explorer. At the top of the hierarchy are the main branches of theRegistry, and each of these categories is called a Hive. Hives are composed ofKeys which can contain other Keys, as well as Values.

Registry Keys aredistinguished depending on their position in the hierarchy, with those at thetop being Root Keys, and those below being Sub Keys.
Registry Values are at the very bottom of the hierarchy and contain the actual information that isbeing stored and referenced in the Registry.

Each of the main branches (orHives/Root Keys) contains a specific portion of the information stored in theRegistry. They are differentiated by the follow characteristics:
  • HKEY_CLASSES_ROOT – This branch contains fileassociation mappings, shortcut destinations, object linking and embedding (OLE)information, and core aspects of the Windows user interface.
  • HKEY_CURRENT_USER – This branch isuser-specific, and links to a section within HKEY_USERS depending on the userthat is currently logged onto the PC, which contains information such as logonnames, desktop settings, and Start menu settings.
  • HKEY_LOCAL_MACHINE – This branch containsmachine-wide information about the specific type of hardware, software, andother preferences on a given PC, and is available to every user who logs ontothe computer.
  • HKEY_USERS – This contains different Sub Keysfor each user and their individual preferences.
  • HKEY_CURRENT_CONFIG – This branch links to a specific section in HKEY_LOCAL_MACHINE depending on the current hardwareconfiguration.
Each Registry value is stored as one of five data types:
  • REG_SZ – This type is a standard string, used to represent human readable text values.
  • REG_BINARY – This type is typically used by hardware components, which store information as raw binary data: 0’s and 1’s.
  • REG_MULTI_SZ – This data type is a multiple string used to represent values that contain lists or multiple values, witheach entry separated by a NULL character.
  • REG_DWORD – This data type is a Double Word,or a 32-bit numeric value, and can hold any number from 0 to 232.
  • REG_EXPAND_SZ – This type is an expandable string that contains a variable that is replaced when called by an application.For example, a value containing the string “%SystemRoot%” will be replaced bythe location of the directory containing system files.

Ways toedit a registry
  • Using Regedit :
  1. Open the start menu.
  2. Choose “Run”.
  3. Write “Regedit” and press Enter.
  4. All the registries can be viewed thereorganized in the hierarchy as discussed above. Just browse the tree structureto see various keys and their value (WORD OF CAUTION: Please don’t try changingvalues here as it may altogether corrupt your OS (though in a worst case)).
  5. For playing with registry I Would suggest adda dummy registry with dummy key and dummy value. Just right click on any tree sub node and give your registry a name.
  6. Now Right click on newly created registry andclick new->String value. Click enter to set key for the registry.
  7. You can see the key on the right pane. Rightclick on the Key and click Modify to set a value for the registry.
  •  Programmatically creating, editing, and deleting registry (Using .NET).
  1. In .NETclassRegistry is located in Microsoft.Win32 namespace.
  2. To create a registry : 

    Here DummyRegistryis the name of the key we want to create.

  3. To edit a registry: First we need to open the sub key and then set its value.
    1. // Step 1. Open the sub key.
      RegistryKeyobjRegistry = Registry.CurrentUser.OpenSubKey("SOFTWARE\DummyRegistry",true);
      // Step 2. Set value of key.
      objRegistry.SetValue("KeyString", "KeyValue", RegistryValueKind.String);
      // Step 3. Close the key.
  4. Don’t forget to write line no. 3 as itsafely saves the key and its value.
This is all about Structure of Windows Registry, its structure and waysto edit them. I hope you all enjoyed reading this article as much as I enjoyed writing it. Please write to us at [email protected] to get the complete codeand all related code files of above written code snippet.

About the Author

- Co-Founder of IdleBrains, is software Engineer by profession with expertise in .NET technologies and data structures. An avid reader and writer, loves to keep himself well versed with new technologies. When not working can be found on Badminton court or chatting with friends. Among other hobbies, loves to listen old hindi numbers of Kishore Kumar and Mukesh.

Leave a Reply

Your email address will not be published. Required fields are marked *

facebook comments: