Click here to Skip to main content
13,667,186 members
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 27 Mar 2007
Licenced CPOL

How to Deal with Windows Registry?

, 27 Mar 2007
Rate this:
Please Sign up or sign in to vote.
Dealing with Registry to Save and Load My Application Settings and to modify Windows Functions


In this article, we will talk about the Registry: What is it? How can we use it? How can developers use the Registry in their applications? How can we use the Registry in organizing our Windows user interface?

What is the Registry?

It is a central hierarchical database used in Microsoft Windows 9X, Windows CE, Windows NT, and Windows 2000 used to store information necessary to configure the system for one or more users, applications and hardware devices.

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.

How can we Modify the Registry?

You can modify the registry by using the registry editor (regedit.exe). Open "Start Menu", then choose "Run…" and type "regedit", then you will get the Registry Editor window on the screen. HOWEVER, if you use Registry Editor incorrectly, you can cause serious problems that may require you to reinstall your operating system.

What will you Get after Opening the Registry Editor?

You will get a tree view in the left-hand side of the editor which has 5 main nodes as follows:

  1. HKEY_CURRENT_USER (which we will use)

    This contains the root of the configuration information for the user who is currently logged on. The user's folders, screen colors, and Control Panel settings are stored here. This information is associated with the user's profile. This key is sometimes abbreviated as "HKCU."


    It contains all the actively loaded user profiles on the computer. HKEY_CURRENT_USER is a sub-key of HKEY_USERS. HKEY_USERS is sometimes abbreviated as "HKU." 


    It contains configuration information particular to the computer, (for any user). This key is sometimes abbreviated as "HKLM." 


    Is a sub key of HKEY_LOCAL_MACHINE\software. The information stored here makes sure that the correct program opens when you open a file by using Windows Explorer. To change the settings for the interactive user, changes must be made under HKEY_CURRENT_USER\Software\Classes instead of under HKEY_CLASSES_ROOT. To change the default settings, changes must be made under HKEY_LOCAL_MACHINE\Software\Classes


    This contains information about the hardware profile that is used by the local computer at system startup.

How can you Use the Registry to Save and Load your Application Settings?

If you use any application like Microsoft Notepad and change the font color and size, then change the size of the Notepad, then drag the Notepad to the top-left corner of the screen and close it, what will you get when you open the Notepad the next time? You will get the Notepad with the same font, font size, size and place as the last time you left it. How can this happen? This is because of using the Registry to save the settings of the application when closing it and loading these settings when opening this application again.

To save your application settings, follow these steps while saving:

  1. You must include the namespace Microsoft.Win32.

  2. Create your own Registry key:

    RegistryKey MyKey = Registry.CurrentUser.CreateSubKey(@"Software\MyApp\");
  3. Set the values you want to add to Registry:

  4. Repeat step 3 for every value you want to add in the Registry.

  5. Don't forget to close your key

  6. Check that the key is created in the Registry. Open the Registry editor and choose the current user node, then the Software subnode and you will find your "MyApp" folder which contains the keys you set. Also, you can change the values you added by just right clicking on the key you want to change and clicking on 'modify'.

To load your application settings which are saved in the Registry, follow these steps:

  1. Don't forget:

    Using Microsoft.Win32;
  2. Create a Registry key:

    RegistryKey MyKey = Registry.CurrentUser.OpenSubKey(@"Software\MyApp\");
  3. To get your values from Registry:

  4. Don't forget also to close your key:


How to Use the Registry to Control your Windows Settings?

You can also use Registry to control your Windows functions, including: Accessories, Appearance, Desktop, File System, LogIn and Authentication, Start Menu and TaskBar, Startup and Shutdown, System, Troubleshooting and finally Windows Explorer.

For example, you want to remove the log off and search from the start menu. How can you do that?

It is very simple. You just need to know the path to where the key is located, the name of the key and the value that you will exchange the current value with. The "search" key is located at "CurrentUser\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\", it's key is called "NoFind" and finally its value is either 1 or 0; 1 for true, (true means that no search button in start menu) and 0 for false, (the search button will be there). The logoff button is at the same path of the search button and its key name is "StartMenuLogoff" with values also 1 or 0, 1 for disabling the logoff button and 0 for enabling it.

This is a code sample for disabling the search and logoff buttons of the start menu:

RegistryKey MyKey = Registry.CurrentUser.CreateSubKey
	(@"Software\ Microsoft\Windows\CurrentVersion\Policies\Explorer\");

Then restart (or logoff) your PC and see what happens. What if you want to get them back? Write the same code but replace the two values from 1 to 0 then restart again and check what happened.

If you are worried about memorizing the key's path, name and value, do not be, you can find all of them here.

I hope this article has been helpful to those of you who wondered what the registry really is, and I urge those of you who have other tid-bits to leave your comments. For those with further queries, please do not hesitate to ask.


  • 27th March, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Moustafa Zain
Web Developer
Egypt Egypt
.NET Developer
Works now as a SoftwareDeveloper and Trainer

BSc Computer and Information Sciences June 2006.


You may also be interested in...

Comments and Discussions

Generalfantstic article Pin
Member 435004212-Jun-08 20:45
memberMember 435004212-Jun-08 20:45 
GeneralRe: fantstic article Pin
Moustafa-Mohammed28-Jun-08 4:10
memberMoustafa-Mohammed28-Jun-08 4:10 
QuestionRegistry or File Pin
NigelAston17-Jul-07 23:03
memberNigelAston17-Jul-07 23:03 
AnswerRe: Registry or File Pin
Moustafa-Mohammed23-Jul-07 2:27
memberMoustafa-Mohammed23-Jul-07 2:27 
Generalhi my problem is also related to parallel port registory Pin
rajbhansingh13-Jul-07 19:52
memberrajbhansingh13-Jul-07 19:52 
QuestionHi Pin
Nilish23-May-07 19:46
memberNilish23-May-07 19:46 
AnswerRe: Hi [modified] Pin
Moustafa-Mohammed28-May-07 6:03
memberMoustafa-Mohammed28-May-07 6:03 
Generalgood job Pin
Islam931-Mar-07 16:06
memberIslam931-Mar-07 16:06 
GeneralRe: good job Pin
Moustafa-Mohammed1-Apr-07 8:27
memberMoustafa-Mohammed1-Apr-07 8:27 
Generalgood job mostafa Pin
metinergoktas30-Mar-07 4:00
membermetinergoktas30-Mar-07 4:00 
GeneralRe: good job mostafa Pin
Moustafa-Mohammed30-Mar-07 6:28
memberMoustafa-Mohammed30-Mar-07 6:28 
Questionhow to protect Pin
Bharaathi29-Mar-07 21:18
memberBharaathi29-Mar-07 21:18 
AnswerRe: how to protect Pin
Moustafa-Mohammed30-Mar-07 6:29
memberMoustafa-Mohammed30-Mar-07 6:29 
AnswerRe: how to protect Pin
Amr Aly Elsehemy31-Mar-07 6:37
memberAmr Aly Elsehemy31-Mar-07 6:37 
AnswerRe: how to protect Pin
Moustafa-Mohammed31-Mar-07 7:55
memberMoustafa-Mohammed31-Mar-07 7:55 
GeneralNice work Mustafa Pin
amjad mohammad29-Mar-07 4:37
memberamjad mohammad29-Mar-07 4:37 
GeneralRe: Nice work Mustafa Pin
Moustafa-Mohammed29-Mar-07 5:11
memberMoustafa-Mohammed29-Mar-07 5:11 
GeneralGood Start Pin
Raghda Amr Salah Eldin28-Mar-07 10:29
memberRaghda Amr Salah Eldin28-Mar-07 10:29 
GeneralRe: Good Start Pin
Moustafa-Mohammed29-Mar-07 3:04
memberMoustafa-Mohammed29-Mar-07 3:04 
GeneralNice demo Pin
Amr Aly Elsehemy28-Mar-07 4:45
memberAmr Aly Elsehemy28-Mar-07 4:45 
GeneralRe: Nice demo Pin
Moustafa-Mohammed28-Mar-07 9:04
memberMoustafa-Mohammed28-Mar-07 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.180820.1 | Last Updated 27 Mar 2007
Article Copyright 2007 by Moustafa Zain
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid