C # operate the registry [copy to backup]

Source: Internet
Author: User
 1 using Microsoft. Win32;
2 using system. diagnostics;
3 private void access_registry ()
4 {
5 // create a new key under hkey_local_machinesoftware and name it mcbinc
6 registrykey key = registry. localmachine. opensubkey ("software", true );
7 // Add a subkey
8 registrykey newkey = key. createsubkey ("mcbinc ");
9
10 // set the value of this subkey
11 newkey. setvalue ("mcbinc", "net developer ");
12
13 // obtain data from other places in the Registry
14
15 // find your CPU
16 registrykey pregkey = registry. localmachine;
17 pregkey = pregkey. opensubkey ("hardwaredescriptionsystemcentralprocessor ");
18 object val = pregkey. getvalue ("vendoridentifier ");
19 Debug. writeline ("the central processor of this machine is:" + val );
20 // Delete the key value
21 registrykey delkey = registry. localmachine. opensubkey ("software", true );
22 delkey. deletesubkey ("mcbinc ");
23}
24

To write the registry:

An error is reported when the registry value is written.

System. unauthorizedaccessexception: cannot be written to the registry key

You can set 2nd parameters to true for the opensubkey () method, and 2nd parameters to true to indicate readable and writable registries.

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.