My.Computer.Registry.GetValue Method
Gets a value from a registry key.
' Usage
Dim value As Object = My.Computer.Registry.GetValue(keyName ,valueName ,defaultValue)
' Declaration
Public Function GetValue( _
ByVal keyName As String, _
ByVal valueName As String, _
ByVal defaultValue As Object _
) As Object
Parameters
- keyName
String. Key from which the value is to be retrieved. Required.
- valueName
String. Value to be retrieved. Required.
- defaultValue
Object. Default value to be supplied if the value does not exist. Required.
Remarks
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 valueName.
Exceptions
The following conditions may cause an exception:
The name of the key is Nothing (ArgumentNullException).
The user does not have permissions to read from registry keys (SecurityException).
The key name exceeds the 255-character limit (ArgumentException).
Tasks
The following table lists examples of tasks involving the GetValue method.
To | See |
---|---|
Read a value from a registry key |
Example
This example reads the value Name
from HKEY_CURRENT_USER\Software\MyApp
and displays it in a MessageBox.
Dim readValue As Object
readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\MyApp", "Name", Nothing)
MsgBox("The value is " & CStr(readValue))
Requirements
Namespace: Microsoft.VisualBasic.MyServices
Class: RegistryProxy (provides access to Registry)
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Permissions
No permissions are required.
See Also
Tasks
Troubleshooting: Manipulating the Registry
Reference
My.Computer.Registry Object
GetValue
Concepts
Common Registry Tasks
Security and the Registry
Reading from and Writing to the Registry Using My