Registry-Important classes and operations:
Microsoft.Win32.Registry: Provides access to the base registrykeys of values and subkeys in the registry, the main methods are CurrentUser (corresponding to the registry HKEY_CURRENT_USER), LocalMachine (corresponding to the HKEY_LOCAL_MACHINE of the Registry)
Microsoft.Win32.RegistryKey: Encapsulates the operation of a registry key. The common method properties are:
1 The operation of the item: OpenSubKey, CreateSubKey, DeleteSubKey, Deletesubkeytree, Getsubkeynames
2 The operation of the value: GetValue, SetValue, DeleteValue, GetValueNames
3) Other operations: Flush, close
4 Common Properties: Name, Subkeycount, Valuecount,
5 ToString: The return value includes the registry path for the specified item and the hexadecimal value of the entry. The registry path includes the absolute root of the specified item, always starting from a base item (such as HKEY_LOCAL_MACHINE) in the registry
1. Access the corresponding registry key for the current application
The registry key for application data can be obtained by the Application.userappdataregistry property. Access to properties can be automatically created in the following registry directory ([] for the corresponding application properties.):
currentuser\software\ [companyname]\ [productname]\ [ProductVersion]
Note that it contains version information for the program, which means that when the program changes, we have to go to the old version of the directory or recreate the value under the new version. So for some version-independent information, it can be stored in the ancestor (currentuser\software\ [companyname]\ [ProductName]).
2. Obtain an item according to the path
The OpenSubKey and CreateSubKey provided by RegistryKey are created only under the current key and cannot be created recursively. To resolve this problem, you can create the following code (the name of the subkey in the keys array that stores the recursion):
Public RegistryKey CreateSubKey (RegistryKey startkey, string[] keys) {
RegistryKey subkey = Startkey;
for (int i=0; I<keys. GetLength (0); i++) {
if (Subkey.opensubkey (keys[i]) = = null) {
subkey = Subkey.opensubkey (Keys[i], true);
} else {
subkey = Subkey.createsubkey (Keys[i]);
}
}
return subkey;
}
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