Retrieves the value associated with the specified name, in the specified registry key. If the name is not found in the specified key, returns a default value that you provide, or null if the specified key does not exist.
null if the subkey specified by keyName does not exist; otherwise, the value associated with valueName, or defaultValue if valueName is not found.
The string valueName is not case-sensitive.
A registry key can contain one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To retrieve this unnamed value, specify either null or the empty string ("") for valuName.
Valid root names are HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG, and HKEY_DYN_DATA. For example, in Visual Basic the string "HKEY_CURRENT_USER\MyTestKey" accesses key/value pairs for the subkey "MyTestKey" in the HKEY_CURRENT_USER root.
When the RegistryKey.GetValue(string) method retrieves expandable string values (RegistryValueKind.ExpandString), it expands environment strings using data from the local environment. If a value containing expandable references to environment variables has been stored as a string (RegistryValueKind.String), rather than as an expandable string (RegistryValueKind.ExpandString), RegistryKey.GetValue(string) does not expand it. You can expand such a string after it has been retrieved by calling the Environment.ExpandEnvironmentVariables(string) method.
The recommended way to retrieve data from HKEY_PERFORMANCE_DATA is to use the System.Diagnostics.PerformanceCounter class rather than the erload:Microsoft.Win32.RegistryKey.GetValue method.
The Registry.GetValue(string, string, object) and erload:Microsoft.Win32.Registry.SetValue methods open and close registry keys each time they are used, so they do not perform as well as the methods of the Microsoft.Win32.RegistryKey class if you access a large number of values.
Microsoft.Win32.RegistryKey also provides methods that allow you to add an access control list (ACL) to a registry key, to test the data type of a value before retrieving it, and to delete keys.