Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RegistryKey.GetValueKind Method (String)


Retrieves the registry data type of the value associated with the specified name.

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

public RegistryValueKind GetValueKind(
	string name


Type: System.String

The name of the value whose registry data type is to be retrieved. This string is not case-sensitive.

Return Value

Type: Microsoft.Win32.RegistryValueKind

The registry data type of the value associated with name.

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 subkey that contains the specified value does not exist.


The name/value pair specified by name does not exist.

This exception is not thrown on Windows 95, Windows 98, or Windows Millennium Edition.


The user does not have the necessary registry rights.


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 the registry data type of this unnamed value, specify either null or the empty string ("") for name.

For a description of supported registry data types, please see the RegistryValueKind enumeration.

The following code example creates a test key and adds values of different data types to the key. The example then reads the name/value pairs and displays them to the console, using the GetValueKind method to retrieve the corresponding registry data types.

using System;
using Microsoft.Win32;

public class Example
    public static void Main()
        // Delete and recreate the test key.
        Registry.CurrentUser.DeleteSubKey("RegistryValueKindExample", false);
        RegistryKey rk = 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.
        string[] valueNames = rk.GetValueNames();
        foreach (string s in valueNames)
            RegistryValueKind rvk = rk.GetValueKind(s);
            switch (rvk)
                case RegistryValueKind.MultiString :
                    string[] values = (string[]) rk.GetValue(s);
                    Console.Write("\r\n {0} ({1}) =", s, rvk);
                    for (int i = 0; i < values.Length; i++)
                        if (i != 0) Console.Write(",");
                        Console.Write(" \"{0}\"", values[i]);

                case RegistryValueKind.Binary :
                    byte[] bytes = (byte[]) rk.GetValue(s);
                    Console.Write("\r\n {0} ({1}) =", s, rvk);
                    for (int i = 0; i < bytes.Length; i++)
                        // Display each byte as two hexadecimal digits.
                        Console.Write(" {0:X2}", bytes[i]);

                default :
                    Console.WriteLine("\r\n {0} ({1}) = {2}", s, rvk, rk.GetValue(s));

This code example produces the following output:
 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.***]



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

.NET Framework
Available since 2.0
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft