Retrieves a specified subkey, and specifies whether write access is to be applied to the key.
Retrieves the specified subkey for read or read/write access, requesting the specified access rights.
Retrieves a subkey with the specified name and access rights. Available starting with .NET Framework 4.6.
Retrieves a subkey as read-only.
Retrieves the specified subkey for read or read/write access.
Name or path of the subkey to open.
Set to true if you need write access to the key.
The subkey requested, or null if the operation failed.
The RegistryKey is closed (closed keys cannot be accessed).
The user does not have the permissions required to access the registry key in the specified mode.
The following code example creates a test key and uses the OpenSubKey method to open it, demonstrating both overloads of the method.
// Delete and recreate the test key.
// Obtain the test key (read-only) and display it.
// Open the test key in read/write mode.
' Delete and recreate the test key.
' Obtain the test key (read-only) and display it.
' Obtain the test key in read/write mode.
If the requested key does not exist, this method returns null instead of throwing an exception.
If writable is true, the key will be opened for reading and writing, otherwise, the key will be opened as read-only.
In order to use the OpenSubKey method, you must have an instance of the RegistryKey method. To get an instance of RegistryKey, use one of the static members of the Registry class.
The name or path of the subkey to create or open.
One of the enumeration values that specifies whether the key is opened for read or read/write access.
A bitwise combination of enumeration values that specifies the desired security access.
permissionCheck contains an invalid value.
rights includes invalid registry rights values.
The user does not have the requested permissions.
Rather than throwing an exception, this method returns null if the requested key does not exist.
If permissionCheck is RegistryKeyPermissionCheck.ReadWriteSubTree, the key is opened for reading and writing; if permissionCheck is RegistryKeyPermissionCheck.ReadSubTree or RegistryKeyPermissionCheck.Default, the key is opened for reading unless the parent key was opened with RegistryKeyPermissionCheck.ReadWriteSubTree.
The access specified for permissionCheck takes precedence over the access specified for rights. For example, if you specify RegistryKeyPermissionCheck.ReadSubTree for permissionCheck and RegistryRights.WriteKey for rights, an attempt to write to the subkey throws an exception.
In order to use the OpenSubKey method, you must have an instance of the RegistryKey class. To get an instance of RegistryKey, use one of the static members of the Registry class.
The rights for the registry key.
You must open a key before it can be manipulated with other methods and properties. To modify a key, you must open it with an overload of the OpenSubKey method that allows you to specify write access.
The name or path of the subkey to open as read-only.
The user does not have the permissions required to read the registry key.
You must open a key before it can be manipulated with other methods and properties. To modify a key, you must open it with an overload of the OpenSubKey method that allows you to specify write access, such as the OpenSubKey(String, RegistryKeyPermissionCheck) overload or the OpenSubKey(String, Boolean) overload.
If the specified subkey cannot be found, then null is returned.
In order to use the OpenSubKey method, you must have an instance of RegistryKey. To get an instance of RegistryKey, use the one of the static members of the Registry class.
The following code example creates a subkey containing 100 key/value pairs and closes it. The example opens the subkey with Default, records the time it takes to read all the values, and closes the subkey. The example opens the subkey with ReadSubTree and records the time it takes to read all the values. Finally, the example computes and displays the percentage improvement.
// a key/value pair is read.
// not checked when the values are read.
ReadSubTree is 23.4% faster for 100 values.
Const testKey As String = "RegistryKeyPermissionCheckExample"
' a key/value pair is read.
' not checked when the values are read.
'ReadSubTree is 23.4% faster for 100 values.