This documentation is archived and is not being maintained.

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.

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.

The following conditions may cause an exception:

The following table lists examples of tasks involving the GetValue method.

To See

Read a value from a registry key

How to: Read a Value from a Registry Key in Visual Basic

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))

Namespace: Microsoft.VisualBasic.MyServices

Class: RegistryProxy (provides access to Registry)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

No permissions are required.

Show: