Export (0) Print
Expand All

RegistryValueKind Enumeration

Note: This enumeration is new in the .NET Framework version 2.0.

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 enum RegistryValueKind
/** @attribute ComVisibleAttribute(true) */ 
public enum RegistryValueKind
ComVisibleAttribute(true) 
public enum RegistryValueKind

 Member nameDescription
Supported by the .NET Compact FrameworkBinarySpecifies binary data in any form. This value is equivalent to the Win32 API registry data type REG_BINARY. 
Supported by the .NET Compact FrameworkDWordSpecifies a 32-bit binary number. This value is equivalent to the Win32 API registry data type REG_DWORD. 
Supported by the .NET Compact FrameworkExpandStringSpecifies a 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. 
Supported by the .NET Compact FrameworkMultiStringSpecifies an array of null-terminated strings, terminated by two null characters. This value is equivalent to the Win32 API registry data type REG_MULTI_SZ. 
Supported by the .NET Compact FrameworkQWordSpecifies a 64-bit binary number. This value is equivalent to the Win32 API registry data type REG_QWORD. 
Supported by the .NET Compact FrameworkStringSpecifies a null-terminated string. This value is equivalent to the Win32 API registry data type REG_SZ. 
Supported by the .NET Compact FrameworkUnknownIndicates an 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. 

The RegistryValueKind enumeration defines the set of supported registry data types and the value that is used for unsupported types (Unknown).

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.

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}) = \"{2}\"", s, rvk, values[0]);
                    for (int i = 1; i < values.Length; i++)
                    {
                        Console.Write(", \"{0}\"", values[i]);
                    }
                    Console.WriteLine();
                    break;
                
                case RegistryValueKind.Binary :
                    byte[] bytes = (byte[]) rk.GetValue(s);
                    Console.Write("\r\n {0} ({1}) = {2:X2}", s, rvk, bytes[0]);
                    for (int i = 1; i < bytes.Length; i++)
                    {
                        // Display each byte as two hexadecimal digits.
                        Console.Write(" {0:X2}", bytes[i]);
                    }
                    Console.WriteLine();
                    break;
                
                default :
                    Console.WriteLine("\r\n {0} ({1}) = {2}", s, rvk, rk.GetValue(s));
                    break;
            }
        }
    }
}

import System.*;
import Microsoft.Win32.*;

public class Example
{
    public static void main(String[] args)
    {
        // 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", (Int32)42, RegistryValueKind.QWord);
        // The following SetValue calls have the same effect as using the
        // SetValue overload that does not specify RegistryValueKind.
        //
        rk.SetValue("DWordValue", (Int32)42, RegistryValueKind.DWord);
        rk.SetValue("MultipleStringValue", new String[] { "One", "Two",
            "Three" }, RegistryValueKind.MultiString);
        rk.SetValue("BinaryValue", new ubyte[] { 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();

        for (int iCtr1 = 0; iCtr1 < valueNames.get_Length(); iCtr1++) {
            String s = valueNames [iCtr1];
            RegistryValueKind rvk = rk.GetValueKind(s);
            switch (rvk) {
                case RegistryValueKind.MultiString:
                    String values[] = (String[])(rk.GetValue(s));
                    Console.Write("\r\n {0} ({1}) = \"{2}\"", s, rvk,
                        values.get_Item(0));
                    for (int i = 1; i < values.get_Length(); i++) {
                        Console.Write(", \"{0}\"", values.get_Item(i));
                    }
                    Console.WriteLine();
                    break;

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

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft