This documentation is archived and is not being maintained.

RegistryValueKind Enumeration

Specifies the data types to use when storing values in the registry, or identifies the data type of a value in the registry.

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

<ComVisibleAttribute(True)> _
Public Enumeration RegistryValueKind

Member nameDescription
StringA null-terminated string. This value is equivalent to the Win32 API registry data type REG_SZ.
ExpandStringA null-terminated string that contains unexpanded references to environment variables, such as %PATH%, that are expanded when the value is retrieved. This value is equivalent to the Win32 API registry data type REG_EXPAND_SZ.
BinaryBinary data in any form. This value is equivalent to the Win32 API registry data type REG_BINARY.
DWordA 32-bit binary number. This value is equivalent to the Win32 API registry data type REG_DWORD.
MultiStringAn array of null-terminated strings, terminated by two null characters. This value is equivalent to the Win32 API registry data type REG_MULTI_SZ.
QWordA 64-bit binary number. This value is equivalent to the Win32 API registry data type REG_QWORD.
UnknownAn unsupported registry data type. For example, the Microsoft Win32 API registry data type REG_RESOURCE_LIST is unsupported. Use this value to specify that the SetValue method should determine the appropriate registry data type when storing a name/value pair.
NoneNo data type.

The RegistryValueKind enumeration defines the set of supported registry data types and the value that is used for unsupported types (Unknown). Starting in the .NET Framework version 4, you can specify not to use a data type with the None value.

Use the RegistryKey.GetValueKind method to determine the data type of a registry key value before retrieving the value. When you set a registry key value, use the SetValue method to specify the registry data type explicitly.

The following code example creates a registry key and sets several values for that key, using RegistryValueKind to specify the registry data types. The example then uses RegistryKey.GetValueKind to check the registry data types, in order to retrieve the values and display them.

Imports System
Imports Microsoft.Win32
Imports Microsoft.VisualBasic

Public Class Example
    Public Shared Sub Main()
        ' Delete and recreate the test key.
        Registry.CurrentUser.DeleteSubKey("RegistryValueKindExample", False)
        Dim rk As RegistryKey = Registry.CurrentUser.CreateSubKey("RegistryValueKindExample")

        ' Create name/value pairs.
        ' This overload supports QWord (long) values. 
        rk.SetValue("QuadWordValue", 42, RegistryValueKind.QWord)

        ' The following SetValue calls have the same effect as using the
        ' SetValue overload that does not specify RegistryValueKind.
        rk.SetValue("DWordValue", 42, RegistryValueKind.DWord)
        rk.SetValue("MultipleStringValue", New String() {"One", "Two", "Three"}, RegistryValueKind.MultiString)
        rk.SetValue("BinaryValue", New Byte() {10, 43, 44, 45, 14, 255}, RegistryValueKind.Binary)
        rk.SetValue("StringValue", "The path is %PATH%", RegistryValueKind.String) 

        ' This overload supports setting expandable string values. Compare
        ' the output from this value with the previous string value.
        rk.SetValue("ExpandedStringValue", "The path is %PATH%", RegistryValueKind.ExpandString)

        ' Display all name/value pairs stored in the test key, with each
        ' registry data type in parentheses.
        Dim valueNames As String() = rk.GetValueNames()
        Dim s As String
        For Each s In  valueNames
            Dim rvk As RegistryValueKind = rk.GetValueKind(s)
            Select Case rvk
                Case RegistryValueKind.MultiString
                    Dim values As String() = CType(rk.GetValue(s), String())
                    Console.Write(vbCrLf & " {0} ({1}) =", s, rvk)
                    For i As Integer = 0 To values.Length - 1
                        If i <> 0 Then Console.Write(",")
                        Console.Write(" ""{0}""", values(i))
                    Next i

                Case RegistryValueKind.Binary
                    Dim bytes As Byte() = CType(rk.GetValue(s), Byte())
                    Console.Write(vbCrLf & " {0} ({1}) =", s, rvk)
                    For i As Integer = 0 To bytes.Length - 1
                        ' Display each byte as two hexadecimal digits.
                        Console.Write(" {0:X2}", bytes(i))
                    Next i

                Case Else
                    Console.WriteLine(vbCrLf & " {0} ({1}) = {2}", s, rvk, rk.GetValue(s))
            End Select
        Next s
    End Sub 'Main
End Class 'Example

'This code example produces the following output (some output is omitted):
' QuadWordValue (QWord) = 42
' DWordValue (DWord) = 42
' MultipleStringValue (MultiString) = "One", "Two", "Three"
' BinaryValue (Binary) = 0A 2B 2C 2D 0E FF
' StringValue (String) = The path is %PATH%
' ExpandedStringValue (ExpandString) = The path is C:\Program Files\Microsoft.NET\SDK\v2.0\Bin;
' [***The remainder of this output is omitted.***]

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.