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