1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Create a Subkey
RegistryKey newKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\SuperSoft\\App");
// Write Values to the Subkey
newKey.SetValue("Value1", "Content1");
newKey.SetValue("Value2", "Content2");
// read Values from the Subkey
if (SubKeyExist("SOFTWARE\\SuperSoft\\App"))
{
RegistryKey myKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\SuperSoft\\App");
string firstApp = (string)myKey.GetValue("Value1");
string secondApp = (string)myKey.GetValue("Value2");
}
else
throw new Exception("Subkey does not exist!");
// Delete the Subkey
if (SubKeyExist("SOFTWARE\\SuperSoft"))
Registry.CurrentUser.DeleteSubKeyTree("SOFTWARE\\SuperSoft");
else
throw new Exception("Subkey does not exist!");
private bool SubKeyExist(string Subkey)
{
// Check if a Subkey exist
RegistryKey myKey = Registry.CurrentUser.OpenSubKey(Subkey);
if (myKey == null)
return false;
else
return true;
}
|