In the articles "how to read Registration Information" and "use Visual C # To delete registration information in the Registry", we have discussed how to use Visual C # To read and delete registration information in the registry, in this article, we will introduce the other two important operations of Visual C # registry programming: creating registration information and modifying registration information.
In the last two articles, we already know that because Visual C # does not have a class library, it passes through.. Net Framework.. Net FrameWork SDK (software development kit) defines some classes to perform registry operations. This is the two classes encapsulated in the namespace Microsoft. Win32: Registry class and RegistryKey class. The RegistryKey class defines two methods to create the primary key, subkey, and key value in the registry. They are the CreateSubValue () method and the SetValue () method. So how to use Visual C # To modify registration information, in this article, we just introduced how to modify the key value in the registry. For primary keys and subkeys, because the. Net FrameWork SDK does not define this method, you cannot safely modify the information in the registry. The following describes how to use Visual C # To create registration information.
I. Visual C # two methods to be called to create and modify registration information:
(1). CreateSubKey (String key) method: This method is a subkey with the name of the created String. Of course, this method not only creates subkeys, but also creates a primary key in the program described below.
(2 ). setValue (String name, String keyvalue) method: This method has two functions: one can be used to rename the key value, and the other can be used to create a new key value. The specific situation is as follows: if this key value exists in the opened subkey, the new value is assigned to it for renaming. If not, a new key value is created.
2. Programming and running environment and preparations:
I> Windows 2000 Server Edition
II>. Net FrameWork SDK Beta 2
III> to modify an existing key value in a program, you must set the location of the key value in advance. Open the Registry Editor and create the aaa sub-key under the "HARDWARE" sub-key under the "HKEY_LOCAL_MACHINE" primary key and create a key value named "bbb" under the sub-key. As shown in: