RegistryValueKind Enumerazione
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica i tipi di dati da utilizzare durante l'archiviazione dei valori nel Registro di sistema o identifica il tipo di dati di un valore nel Registro di sistema.
public enum class RegistryValueKind
[System.Runtime.InteropServices.ComVisible(true)]
public enum RegistryValueKind
[<System.Runtime.InteropServices.ComVisible(true)>]
type RegistryValueKind =
Public Enum RegistryValueKind
- Ereditarietà
- Attributi
Campi
| Nome | Valore | Descrizione |
|---|---|---|
| None | -1 | Nessun tipo di dati. |
| Unknown | 0 | Tipo di dati del Registro di sistema non supportato. Ad esempio, il tipo di dati del Registro di sistema dell'API Microsoft Windows REG_RESOURCE_LIST non è supportato. Usare questo valore per specificare che il SetValue(String, Object) metodo deve determinare il tipo di dati del Registro di sistema appropriato durante l'archiviazione di una coppia nome/valore. |
| String | 1 | Stringa con terminazione Null. Questo valore equivale al tipo di dati del Registro di sistema dell'API Windows REG_SZ. |
| ExpandString | 2 | Stringa con terminazione Null che contiene riferimenti non espansi alle variabili di ambiente, ad esempio %PATH%, espanse quando viene recuperato il valore. Questo valore equivale al tipo di dati del Registro di sistema dell'API Windows REG_EXPAND_SZ. |
| Binary | 3 | Dati binari in qualsiasi formato. Questo valore equivale al tipo di dati del Registro di sistema dell'API Windows REG_BINARY. |
| DWord | 4 | Numero binario a 32 bit. Questo valore equivale al tipo di dati del Registro di sistema dell'API Windows REG_DWORD. |
| MultiString | 7 | Matrice di stringhe con terminazione Null, terminate da due caratteri Null. Questo valore equivale al tipo di dati del Registro di sistema dell'API Windows REG_MULTI_SZ. |
| QWord | 11 | Numero binario a 64 bit. Questo valore equivale al tipo di dati del Registro di sistema dell'API Windows REG_QWORD. |
Esempio
Nell'esempio di codice seguente viene creata una chiave del Registro di sistema e vengono impostati diversi valori per tale chiave, usando RegistryValueKind per specificare i tipi di dati del Registro di sistema. L'esempio usa RegistryKey.GetValueKind quindi per controllare i tipi di dati del Registro di sistema, per recuperare i valori e visualizzarli.
using namespace System;
using namespace Microsoft::Win32;
int 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", gcnew array<String^>{
"One","Two","Three"
}, RegistryValueKind::MultiString );
rk->SetValue( "BinaryValue", gcnew array<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 the name/value pairs stored in the test key, with the
// registry data type in parentheses.
//
array<String^>^valueNames = rk->GetValueNames();
System::Collections::IEnumerator^ myEnum = valueNames->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ s = safe_cast<String^>(myEnum->Current);
RegistryValueKind rvk = rk->GetValueKind( s );
switch ( rvk )
{
case RegistryValueKind::MultiString:
{
array<String^>^values = (array<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 ] );
}
Console::WriteLine();
break;
}
case RegistryValueKind::Binary:
{
array<Byte>^bytes = (array<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 ] );
}
Console::WriteLine();
break;
}
default:
Console::WriteLine( "\r\n {0} ({1}) = {2}", s, rvk, rk->GetValue( s ) );
break;
}
}
}
/*
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.***]
*/
using System;
using Microsoft.Win32;
class RegGetDef
{
public static void Main()
{
// Create a reference to a valid key. In order for this code to
// work, the indicated key must have been created previously.
// The key name is not case-sensitive.
RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\myTestKey", false);
// Get the value from the specified name/value pair in the key.
string valueName = "myTestValue";
Console.WriteLine("Retrieving registry value ...");
Console.WriteLine();
object o = rk.GetValue(valueName);
Console.WriteLine("Object Type = " + o.GetType().FullName);
Console.WriteLine();
switch (rk.GetValueKind(valueName))
{
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
Console.WriteLine("Value = " + o);
break;
case RegistryValueKind.Binary:
foreach (byte b in (byte[])o)
{
Console.Write("{0:x2} ", b);
}
Console.WriteLine();
break;
case RegistryValueKind.DWord:
Console.WriteLine("Value = " + Convert.ToString((int)o));
break;
case RegistryValueKind.QWord:
Console.WriteLine("Value = " + Convert.ToString((Int64)o));
break;
case RegistryValueKind.MultiString:
foreach (string s in (string[])o)
{
Console.Write("[{0:s}], ", s);
}
Console.WriteLine();
break;
default:
Console.WriteLine("Value = (Unknown)");
break;
}
// Attempt to retrieve a value that does not exist; the specified
// default value is returned.
string def = (string)rk.GetValue("notavalue", "The default to return");
Console.WriteLine();
Console.WriteLine(def);
rk.Close();
}
}
/*
Output:
Retrieving registry value ...
Object Type = System.String
Value = testData
The default to return
*/
Imports Microsoft.Win32
Public Class RegGetDef
Public Shared Sub Main()
' Create a reference to a valid key. In order for this code to
' work, the indicated key must have been created previously.
' The key name is not case-sensitive.
Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\myTestKey", false)
' Get the value from the specified name/value pair in the key.
Dim valueName As String = "myTestValue"
Console.WriteLine("Retrieving registry value ...")
Console.WriteLine()
Dim o As Object = rk.GetValue(valueName)
Console.WriteLine("Object Type = " + o.GetType().FullName)
Console.WriteLine()
Select Case rk.GetValueKind(valueName)
Case RegistryValueKind.String
Case RegistryValueKind.ExpandString
Console.WriteLine("Value = " + o)
Case RegistryValueKind.Binary
For Each b As Byte In CType(o,Byte())
Console.Write("{0:x2} ", b)
Next b
Console.WriteLine()
Case RegistryValueKind.DWord
Console.WriteLine("Value = " + Convert.ToString(CType(o,Int32)))
Case RegistryValueKind.QWord
Console.WriteLine("Value = " + Convert.ToString(CType(o,Int64)))
Case RegistryValueKind.MultiString
For Each s As String In CType(o,String())
Console.Write("[{0:s}], ", s)
Next s
Console.WriteLine()
Case Else
Console.WriteLine("Value = (Unknown)")
End Select
' Attempt to retrieve a value that does not exist; the specified
' default value is returned.
Dim Def As String = rk.GetValue("notavalue", "The default to return")
Console.WriteLine()
Console.WriteLine(def)
rk.Close()
End Sub
End Class
'
' Output:
' Retrieving registry value ...
'
' Object Type = System.String
'
' Value = testData
'
'The default to return
Commenti
L'enumerazione RegistryValueKind definisce il set di tipi di dati del Registro di sistema supportati e il valore usato per i tipi non supportati (Sconosciuto). A partire da .NET Framework 4, è possibile specificare di non usare un tipo di dati con il valore Nessuno.
Utilizzare il RegistryKey.GetValueKind metodo per determinare il tipo di dati di un valore della chiave del Registro di sistema prima di recuperare il valore. Quando si imposta un valore di chiave del Registro di sistema, usare il SetValue metodo per specificare il tipo di dati del Registro di sistema in modo esplicito.