Library tutorials & articles

Registry In's and Out's Using C#

Introduction

This is an article on using the Registry in C#. Having been looking around the web and on the MSDN libraries, I have determined that there is not a complete guide on using all the registry tools accessible using C#. So this article is going to cover all methods exposed to the user when developing in C#. Firstly I would like to say that I am very aware that the current consensus is that we should not be using the Registry to hold information about our programs anymore and that the ".NET" way is to store information in XML files. Well if that is you then you don't really need this article, however if you are accessing information from the registry then this is the source for you. Ok so lets get down to business.

When using the .NET framework in C# the user needs to add access to the Microsoft.Win32 namespace in order to access registry manipulation tools, this is done as shown in the below code:

using Microsoft.Win32;

Once this reference has been added along with the other, it gives us access to the elements involved within registry control. There are two main classes associated with this namespace, RegistryKey and Registry. These classes are used together to allow us to do pretty much everything in the registry.

Registry Class

The Registry Class itself on its own doesn't do a lot for us this is because the Registry Class merely represents the seven top-level nodes within the registry for us to access and manipulate. The Registry class is powerful when used with the RegistryKey class. However if you open up Visual Studio.NET and add the namespace above and then just type, "Registry." you will see the list of the seven subnodes (Shown below).

Registry Class name Registry Value What is does
Registry.ClassesRoot HKEY_CLASSES_ROOT Responsible for telling the shell how to handle different file formats
Registry.CurrentConfig HKEY_CURRENT_CONFIG Represents the current session configuration
Registry.CurrentUser HKEY_CURRENT_USER Represents the profile of the current user
Registry.DynData HKEY_DYN_DATA Contains configuration data about dynamic data (i.e. in RAM)
Registry.LocalMachine HKEY_LOCAL_MACHINE Contains the System Information (i.e. Hardware)
Registry.PerformanceData HKEY_PERFORMANCE_DATA Contain information about the performance of applications
Registry.Users HKEY_USERS A repository for information regarding users and their preferences.

Now the we have identified what the Registry Class does and represents we can look at it's partner the RegistryKey Class.

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Registry In's and Out's Using C#.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner

    One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!