Sunday, February 26, 2006 1:05 PM
by
sanyam
RegistryKey Class
Lets have a look at Reading and Writing Registry entries using .Net.
RegistryKeys are the base unit of organization in the registry, and can be compared to folders in Windows Explorer. A particular key can have subkeys (just as a folder can have subfolders), and can be deleted, as long as the user has the appropriate permissions to do so, and the key is not a base key, or the level directly under the base keys. Each key can also have multiple values associated with it (a value can be compared to a file), which are used to store the information about the application you are interested in.
msdn link
example in C#
[C#]
using System;
using System.Security.Permissions;
using Microsoft.Win32;
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
All = "HKEY_CURRENT_USER")]
class RegKey
{
static void Main()
{
// Create a subkey named Test9999 under HKEY_CURRENT_USER.
RegistryKey test9999 = Registry.CurrentUser.CreateSubKey("Test9999");
// Create two subkeys under HKEY_CURRENT_USER\Test9999. The
// keys are disposed when execution exits the using statement.
using(RegistryKey
testName = test9999.CreateSubKey("TestName"),
testSettings = test9999.CreateSubKey("TestSettings"))
{
// Create data for the TestSettings subkey.
testSettings.SetValue("Language", "French");
testSettings.SetValue("Level", "Intermediate");
testSettings.SetValue("ID", 123);
testSettings.SetValue("Password", "Secret");
}
// Print the information from the Test9999 subkey.
Console.WriteLine("There are {0} subkeys under {1}.",
test9999.SubKeyCount.ToString(), test9999.Name);
foreach(string subKeyName in test9999.GetSubKeyNames())
{
using(RegistryKey
tempKey = test9999.OpenSubKey(subKeyName))
{
Console.WriteLine("\nThere are {0} values for{1}.",
tempKey.ValueCount.ToString(), tempKey.Name);
foreach(string valueName in tempKey.GetValueNames())
{
Console.WriteLine("{0,-8}: {1}", valueName,
tempKey.GetValue(valueName).ToString());
}
}
}
}