C # Read and create a registry

Source: Internet
Author: User

 

In C #, registry operations use the RegistryKey class to create, read, and determine whether a certain item exists.

1. Read the value of a certain item to determine whether. NET Framework 2.0.50727 is installed.

Check whether. net is installed. Check whether the value of Install in HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ NET Framework Setup \ NDP \ v2.0.50727 is 1. So how to read it? The following code can be implemented.

 

 

RegistryKey machinelocalItem;

 

RegistryKey softwareItem;

 

RegistryKey microSoftItem;

 

RegistryKey docNetItem;

RegistryKey ndpItem;

RegistryKey versionItem;

 

MachinelocalItem = Registry. LocalMachine;

 

SoftwareItem = machinelocalItem. OpenSubKey ("SOFTWARE ");

 

MicroSoftItem = softwareItem. OpenSubKey ("Microsoft ");

 

DocNetItem = microSoftItem. OpenSubKey ("NET Framework Setup ");

 

NdpItem = docNetItem. OpenSubKey ("NDP ");

 

VersionItem = ndpItem. OpenSubKey ("v2.0.50727" true );

 

Object installValue = netItem. GetValue ("Install ");

 

;

RegistryKey machinelocalItem;

 

RegistryKey softwareItem;

RegistryKey microSoftItem;

RegistryKey docNetItem;

RegistryKey ndpItem;

RegistryKey versionItem;

MachinelocalItem = Registry. LocalMachine;

SoftwareItem = machinelocalItem. OpenSubKey ("SOFTWARE ");

MicroSoftItem = softwareItem. OpenSubKey ("Microsoft ");

DocNetItem = microSoftItem. OpenSubKey ("NET Framework Setup ");

NdpItem = docNetItem. OpenSubKey ("NDP ");

VersionItem = ndpItem. OpenSubKey ("v2.0.50727" true );

Object installValue = netItem. GetValue ("Install ");

 

 

Read completed. Of course, these items are known to exist. If you are not sure about the items, you can determine whether the items to be read are NULL when using OpenSubKey.

2. Create an item.

Or the above example is created.

 

 

RegistryKey machinelocalItem;

 

RegistryKey softwareItem;

 

RegistryKey microSoftItem;

 

RegistryKey docNetItem;

RegistryKey ndpItem;

RegistryKey versionItem;

MachinelocalItem = Registry. LocalMachine;

SoftwareItem = machinelocalItem. CreateSubKey ("Software ");

MicroSoftItem = softwareItem. CreateSubKey ("Microsoft ");

DocNetItem = microSoftItem. CreateSubKey ("NET Framework Setup ");

NdpItem = docNetItem. CreateSubKey ("NDP ");

VersionItem = ndpItem. CreateSubKey ("v2.0.50727 ");

 

VersionItem. SetValue ("Install", 1 );

RegistryKey machinelocalItem;

 

RegistryKey softwareItem;

RegistryKey microSoftItem;

RegistryKey docNetItem;

RegistryKey ndpItem;

RegistryKey versionItem;

MachinelocalItem = Registry. LocalMachine;

SoftwareItem = machinelocalItem. CreateSubKey ("Software ");

MicroSoftItem = softwareItem. CreateSubKey ("Microsoft ");

DocNetItem = microSoftItem. CreateSubKey ("NET Framework Setup ");

NdpItem = docNetItem. CreateSubKey ("NDP ");

VersionItem = ndpItem. CreateSubKey ("v2.0.50727 ");

VersionItem. SetValue ("Install", 1 );

 

 

Created and assigned values.

From Poplar

Related Article

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.