New Message on dotNET User Group Hyd

Article : Access Win Registry through .NET

Reply
  Reply to Sender   Recommend Message 1 in Discussion
From: Nasha

Hi Frndz,

Registry has been a central repository for a lot of Microsoft applications
over the years. You can access a machine's registry using the regedit tool.
. NET also provides us with classes named RegistryKey and Registry under
Microsoft.Win32 namespace to access registry.

Registry class exposes all the main key of the registry i.e. CurrentUser,
CurrentConfig, LocalMachine, CurrentConfig, ClassesRoot and Users as
Registry.CurrentUser, Registry.CurrentConfig, Registry.LocalMachine,
Registry.CurrentConfig, Registry.ClassesRoot and Registry.Users.

There are methods to get any sub key under any of the main keys (the ones
mentioned above).

You can retrieve reference to the main and then retrieve the list of sub
keys under it.

E.g. Here I am retrieving reference to the registry key CurrentUser and then
retrieve the list of sub keys under it.

RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software");
string[] keys = rk.GetSubKeyNames(); // returns an array of sub key names.

Note: In the above code retrieving a reference to the Current User Registry
Key returns me an Registry Key object. To retrieve any detail of that
registry key I need to call methods registry key object.

You can retrieve the sub key count calling the SubKeyCount () method on
registry key object.

To create a sub key under any registry key retrieve the reference to that
registry key and call CreateSubKey() method.

E.g. Here I am creating a sub key named "Nasha" under the
Root\CurrentUser\Software.

RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software",true);
RegistryKey subkey = rk.CreateSubKey("Nasha");

Remember whenever you open a key to create keys under it pass the second
value as true. Passing the second value as true will grant you a write
access. CreateSubkey method returns reference to the new key. Thus you can
use this reference to create nested keys.

To create values under that key node call the Setvalue() method and pass the
name and value parameters.

rk.SetValue("abcd","abcd");

To delete keys and values there are methods like DeleteSubKey(),
DeleteSubKeyTree(), DeleteValue().

There are a lot of other useful methods like GetValueNames() and
GetSubKeyNames() and properties like rk.ValueCount and rk.SubKeyCount.

After you are through with your manipulation dont forget to close the key
with

rk.Close();

-- Please post your queries and comments for my articles in the user group
for the benefit of all. I hope this step from my end is helpful to all of
us. You can find all articles written by me at my personal Blog
http://spaces.msn.com/members/nasha .

Regards,

Namratha (Nasha)



View other groups in this category.

Click here
Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to