RegistryKey.GetValue Method (String, Object, RegistryValueOptions)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Namespace:   Microsoft.Win32
Assembly:  mscorlib (in mscorlib.dll)

member GetValue : 
        name:string *
        defaultValue:Object *
        options:RegistryValueOptions -> Object


Type: System.String

The name of the value to retrieve. This string is not case-sensitive.

Type: System.Object

The value to return if name does not exist.

Type: Microsoft.Win32.RegistryValueOptions

One of the enumeration values that specifies optional processing of the retrieved value.

Return Value

Type: System.Object

The value associated with name, processed according to the specified options, or defaultValue if name is not found.

Exception Condition

The user does not have the permissions required to read from the registry key.


The RegistryKey that contains the specified value is closed (closed keys cannot be accessed).


The RegistryKey that contains the specified value has been marked for deletion.


options is not a valid RegistryValueOptions value; for example, an invalid value is cast to RegistryValueOptions.


The user does not have the necessary registry rights.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

Use the defaultValue parameter to specify the value to return if name does not exist.


A registry key can have 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 name.

GetValue does not support reading values of type REG_NONE or REG_LINK. In both cases, the default value (null) is returned instead of the actual value.

The following code sample creates a test key, adds a value with an embedded environment variable, and retrieves the value in both expanded and unexpanded forms.

No code example is currently available or this language may not be supported.


to read from the registry. Associated enumeration: RegistryPermissionAccess.Read


to read a registry key of type REG_EXPAND_SZ. Associated enumeration: PermissionState.Unrestricted

.NET Framework
Available since 2.0
Return to top