向注册表读取一个键值:
1RegistryKey rstryKey = Registry.LocalMachine;
2 RegistryKey rgstryKeyValues = rstryKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion");
3
4 Response.Write("ProductId = " + rgstryKeyValues.GetValue("ProductId"));
5 Response.Write("");
6
7 Response.Write("ProgramFilesDir = " + rgstryKeyValues.GetValue("ProgramFilesDir"));
8 Response.Write("");
9
10 Response.Write("ProgramFilesPath = " + rgstryKeyValues.GetValue("ProgramFilesPath"));
11 Response.Write("");
12
13 Response.Write("MediaPath = " + rgstryKeyValues.GetValue("MediaPath"));
14 Response.Write("");
15
16 rgstryKeyValues.Close();
17
18
2 RegistryKey rgstryKeyValues = rstryKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion");
3
4 Response.Write("ProductId = " + rgstryKeyValues.GetValue("ProductId"));
5 Response.Write("");
6
7 Response.Write("ProgramFilesDir = " + rgstryKeyValues.GetValue("ProgramFilesDir"));
8 Response.Write("");
9
10 Response.Write("ProgramFilesPath = " + rgstryKeyValues.GetValue("ProgramFilesPath"));
11 Response.Write("");
12
13 Response.Write("MediaPath = " + rgstryKeyValues.GetValue("MediaPath"));
14 Response.Write("");
15
16 rgstryKeyValues.Close();
17
18
向注册表写入一个键值
1rstryKey = Registry.CurrentUser;
2rgstryKeyValues = rstryKey.OpenSubKey("SOFTWARE");
3RegistryKey rgstrySetKey = rgstryKeyValues.CreateSubKey("TestKeyDirectory");
4rgstrySetKey.SetValue("Key1","Key1Value");
5rgstrySetKey.SetValue("Key2","Key2Value");
6rgstrySetKey.SetValue("Key3",3);
2rgstryKeyValues = rstryKey.OpenSubKey("SOFTWARE");
3RegistryKey rgstrySetKey = rgstryKeyValues.CreateSubKey("TestKeyDirectory");
4rgstrySetKey.SetValue("Key1","Key1Value");
5rgstrySetKey.SetValue("Key2","Key2Value");
6rgstrySetKey.SetValue("Key3",3);