1 Abstract
2C # encapsulates registry operations. Operations on Windows Registry become abnormal and simple. This program implements operations such as the creation, modification, and deletion of the Putty registry, which is a good application example.
3 Introduction
The Registry class of 4C # provides the RegistryKey object of the Windows Registry root item, and provides methods for static access items/values. For example, for putty, the root of our operation can be:
5 RegistryKey rkRoot = Registry. CurrentUser. OpenSubKey ("Software"). OpenSubKey ("SimonTatham"). OpenSubKey ("PuTTY"). OpenSubKey ("Sessions ");
6
7. session management is the main goal of the program.
8RegistryKey indicates the entry-level node in the Windows registry. You need to use the following methods to perform value operations:
9 OpenSubKey
10 CreateSubKey
11 SetValue
12 GetValue
13 Close
14. Modify the item Value
15. The instance code changes all rlogin-based session users/passwords to root/123456.
16 const string key1_name = "UserName ";
17 const string key2_name = "UserPasswd ";
18
19 RegistryKey rkRoot =
20 Registry. CurrentUser. OpenSubKey ("Software"). OpenSubKey ("SimonTatham"). OpenSubKey ("PuTTY"). OpenSubKey ("Sessions ");
21 for (int I = 0; I <listBox4.SelectedItems. Count; I ++)
22 {
23 string ss = (string) listBox4.SelectedItems [I];
24 listBox1.Items. Add ("handling session:" + ss );
25 RegistryKey rkSession = rkRoot. OpenSubKey (ss, RegistryKeyPermissionCheck. ReadWriteSubTree );
26 // determine whether it is rlogin
27 if (val_protocol = (string) rkSession. GetValue (key_protocol ))
28 {
29 // Change User Name/Password
30 rkSession. SetValue (key1_name, textBox1.Text );
31 rkSession. SetValue (key2_name, textBox2.Text );
32}
33 else
34 {
35 listBox1.Items. Add ("does not handle" + ss + "because it is not a rlogin type session .");
36}
37 rkSession. Close ();
38}
39 create item Value
40 this program supports dumping the registry and load, which is actually created.
41 string sn = (string) listBox3.SelectedItems [I];
42 RegistryKey rkSn = rkRoot. OpenSubKey (sn, RegistryKeyPermissionCheck. ReadWriteSubTree );
43 listBox1.Items. Add ("handling" + sn );
44 ArrayList al = (ArrayList) session_datas [sn];
45 for (int j = 0; j <al. Count; j ++)
46 {
47 ArrayList items = (ArrayList) al [j];
48 string subkey = (string) (items [0]);
49 RegistryValueKind rvk = (RegistryValueKind) items [1];
50 string v = (string) items [2];
51 if (rvk = RegistryValueKind. DWord)
52 {
53