Click here to Skip to main content
13,351,239 members (50,001 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 14 Apr 2008

How to Program for Windows Registry

, 16 Mar 2010
Rate this:
Please Sign up or sign in to vote.
This article will guide you how to create/retrieve/delete key entries in Windows Registry.


This article will guide you how to use Windows Registry to store user specific non critical data which can be retrieved across applications.


The Registry is split into a number of logical sections better known as hives. A registry hive is a group of keys, subkeys, and values. While programming for our applications, we need to store application specific data. That usually goes in ‘software’ subtree of HKEY_CURRENT_USER hive or HKEY_CURRENT_USER\Software. The supporting files for this hive goes in %SystemRoot%\Profiles\Username folder. While the supporting files for all other hives go in %SystemRoot%\System32\Config folder.

Using the Code

To use Registry in VB.NET, you first have to imports Microsoft.Win32 namespace. This will provide an access to RegistryKey class.

Create Registry Key

'Create a SubKey under Software subtree of HKEY_CURRENT_USER hive.	
Dim vRegistryKey As RegistryKey
vRegistryKey = Registry.LocalMachine.OpenSubKey("Software", True)

'Open Newly created SubKey and insert values using SetValue() method.	
Dim vRegistryKey1 As RegistryKey
vRegistryKey1 = Registry.LocalMachine.OpenSubKey("Software\NewKey", True)
vRegistryKey1.SetValue("Key Name", txtKeyName.Text)
vRegistryKey1.SetValue("Key Description", txtKeyDescription.Text)

Retrieve Existing Registry Key

'Open required SubKey and use GetValue() method to fetch key values.	
Dim vRegistryKey As RegistryKey
vRegistryKey = Registry.LocalMachine.OpenSubKey("Software\NewKey", True)
txtKeyName.Text = vRegistryKey.GetValue("Key Name").ToString
txtKeyDescription.Text = vRegistryKey.GetValue("Key Description").ToString

Delete Existing Registry Key

'Open required SubKey and use DeleteSubKey() method to delete subkey.	
Dim vRegistryKey As RegistryKey
vRegistryKey = Registry.LocalMachine.OpenSubKey("Software", True)

Points to Note

In the provided download sample, when you'll create an Item, please enter a valid Server/IP Address (you can enter 'localhost'), otherwise an error will be shown.

Final Words

I hope you will find this article helpful in programming for Registry Keys. For more information, you can check out the demo program available in the downloads section or you can contact me on

Good luck!


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


About the Author

Mohd Arshad (Sam)
Software Developer (Senior) Cherisys Technologies,
India India

Software professional with demonstrated strength in windows-based and web-based software development. Have 4 years of experience with the full software development lifecycle including requirements, design, development, testing/QA, deployment, training & support. Have 1 year experience managing groups, planning and executing implementations. Practical working knowledge of all aspects of IT. Possess strong insight into practical business considerations.

You may also be interested in...

Comments and Discussions

GeneralReally a great work Pin
pamperghost3-Apr-10 2:55
memberpamperghost3-Apr-10 2:55 
GeneralRe: Really a great work Pin
Mohd Arshad (Sam)3-Apr-10 5:28
memberMohd Arshad (Sam)3-Apr-10 5:28 
QuestionHow to Insert Binary and DWORD data Pin
eg_Anubhava27-Mar-10 3:23
membereg_Anubhava27-Mar-10 3:23 
Hello Sam,

How to insert the Binary data or DWORD data in registry?
IS any option for Saving OLE Data to save in registry ?
Can we crate our own data type to store in registry?

If you can think then I Can.

GeneralMy vote of 1 Pin
SalarSoft16-Mar-10 20:10
memberSalarSoft16-Mar-10 20:10 
GeneralGood article. Pin
Rajib Ahmed9-Jul-08 20:47
memberRajib Ahmed9-Jul-08 20:47 
General[Message Removed] Pin
Mojtaba Vali25-May-08 1:49
memberMojtaba Vali25-May-08 1:49 
QuestionAre you trying to rewrite the MSDN? Pin
sk8er_boy28722-May-08 2:45
membersk8er_boy28722-May-08 2:45 
GeneralNice Pin
Neo-Code6-May-08 11:01
memberNeo-Code6-May-08 11:01 

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 | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 16 Mar 2010
Article Copyright 2008 by Mohd Arshad (Sam)
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid