Use Visual C # to delete registration information in the registry

Source: Internet
Author: User
In the document "read registration information with Visual C #", we have introduced how to use Visual C # to read registration information in the registry. This article introduces another operation on the registry using Visual C #, which is also a destructive operation process-delete registration information.
As we can see above, because Visual C # does not contain a class library, the process of processing the registry is called.. Net FrameWork SDK. the two classes encapsulated in Win32 are implemented. These two classes are the Registry class and RegistryKey class. The RegistryKey class defines three methods to delete registration information in the registry. They are: DeleteSubKey () method, DeleteSubKeyTree () method, and DeleteValue () method. The following describes how to correctly use these three methods in Visual C.
I. How to call these three methods in Visual C:
Before introducing how to use these three methods, you need to re-introduce an OpenSubKey () method in the RegistryKey class. As described in the previous article, this method is to open the specified sub-key. In fact, the OpenSubKey () method can be called in two ways:
I>. OpenSubKey (string, subkey): this call method only performs read operations on this subkey.
II>. OpenSubKey (string subkey, Boolean writable): This method is used when the child key uses the write operation. If you use the write operation on the child key but still use the first call method, an error message is generated when the program is running.
(1). DeleteSubKey () method:
This method deletes a specified sub-key. If another sub-key exists in this sub-key, an error message is generated. There are two prototype for calling this method in a program:
I>. DeleteSubKey (string, subkey): this call method is to directly delete the specified subkey.
II>. deleteSubKey (string subkey, Boolean info): "string" indicates the name of the subkey to be deleted. The "Boolean" parameter indicates that if the value is "True ", when a program is called, if the deleted sub-key does not exist, an error message is generated. If the value is "False", the deleted sub-key does not exist during the program call, no error message is generated, and the program still runs correctly. Therefore, in the specific program design process, I recommend using the second call method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.