Working With Windows Registry Using C# (Part 1: Windows Registry Basics)


In this article I will teach you about how to work with windows registry by windows GUI as this is First article of this series i will teach you basic here that we can manipulate registry normally in windows .In second part of article we will do all the operation we performed here manually we will do it programatically using C#.


What is registry?

 

Registry is place where windows stores its own configuration .like you click some options for task bar "auto hide" etc that all are stored in registry. When windows load again it knows what where the configurations of particular dialog box from the Registry.

 

You can access registry by Start>>Run>>regedit "Hit Enter"

You will see some screen like below


image1.gif


Main parts of Registry to work with

 

Here you can see Current User, Local Machine Users etc part of it .For us important one are Current User and Local Machine .All the settings for current login are stored into HKEY_CURRENT_USER that settings are applicable to only current user Settings that are applicable to the entire user Accounts on machine are stored into HKEY_LOCAL MACHINE.

 

How Registry help us in our software?

 

Registry is place where we can store settings for our application .we can also use XML file to store settings about our application .but when some data you want to store about application that need to be checked every time user opens application and you don't want user to know from where its loading settings best place to store this type of settings into registry .For example MS Office package store its serial Number of Product Activation in Registry.

 

Operations on Registry 


Operation
What it does
Creating Subkey
means Creating Folder in Registry
Opening Subkey
means to Open Folder for Modifying values inside it
Delete Subkey
Delete Folder in registry

now lets get clear Idea what is Opening/Creating Subkey ?

for modifying values(settings of some application in Registry) we need to programatically open the SubKey(Folder) od registry is called Opening Subkey.

We need to create Directory inside windows registry so that we can place settings for our custom application and we do create new registry Subkey for that because we don't want to mess other setting around in registry so we make separate directory for our own settings.

as soon as we don't need registry when we uninstall our application our setup should automatically delete all the registry settings it created without affecting other SubKeys inside registry we use Delete SubKey Operation

So now you have Some Basic Idea About registry how it works .

8-17-2010 12-36-34 PM.gif

[Creating Subkey In Windows Registry ]

8-17-2010 12-38-41 PM.gif
[Delete SubKey in Windows Registry ]

same way you can also work with values too inside the subkeys .like delete /create New values etc

so you have learnt how to manipulate registry of windows manually
Continue ... .
In second part of article we will do all the operation we performed here manually we will do it programatically using C#.


Similar Articles