RegistryValueOptions 枚举
定义
指定从注册表项检索名称/值对时的可选行为。Specifies optional behavior when retrieving name/value pairs from a registry key.
此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。
public enum class RegistryValueOptions
[System.Flags]
public enum RegistryValueOptions
type RegistryValueOptions =
Public Enum RegistryValueOptions
- 继承
- 属性
字段
DoNotExpandEnvironmentNames | 1 | 检索类型为 ExpandString 的值,而不扩展它的嵌入式环境变量。A value of type ExpandString is retrieved without expanding its embedded environment variables. |
None | 0 | 未指定可选行为。No optional behavior is specified. |
示例
下面的代码示例创建一个测试键, 添加一个具有嵌入的环境变量的值, 并在展开和未展开的窗体中检索值。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.
#using <Microsoft.VisualBasic.dll>
using namespace System;
using namespace Microsoft::Win32;
using namespace Microsoft::VisualBasic;
int main()
{
// Delete and recreate the test key.
Registry::CurrentUser->DeleteSubKey( L"RegistryValueOptionsExample", false );
RegistryKey ^ rk =
Registry::CurrentUser->CreateSubKey( L"RegistryValueOptionsExample" );
// Add a value that contains an environment variable.
rk->SetValue( L"ExpandValue", L"The path is %PATH%",
RegistryValueKind::ExpandString );
// Retrieve the value, first without expanding the environment
// variable and then expanding it.
Console::WriteLine( L"Unexpanded: \"{0}\"",
rk->GetValue( L"ExpandValue",
L"No Value",
RegistryValueOptions::DoNotExpandEnvironmentNames ) );
Console::WriteLine( L"Expanded: \"{0}\"", rk->GetValue( L"ExpandValue" ) );
return 0;
} //Main
using System;
using Microsoft.Win32;
using Microsoft.VisualBasic;
public class Example
{
public static void Main()
{
// Delete and recreate the test key.
Registry.CurrentUser.DeleteSubKey("RegistryValueOptionsExample", false);
RegistryKey rk =
Registry.CurrentUser.CreateSubKey("RegistryValueOptionsExample");
// Add a value that contains an environment variable.
rk.SetValue("ExpandValue", "The path is %PATH%", RegistryValueKind.ExpandString);
// Retrieve the value, first without expanding the environment
// variable and then expanding it.
Console.WriteLine("Unexpanded: \"{0}\"",
rk.GetValue("ExpandValue", "No Value",
RegistryValueOptions.DoNotExpandEnvironmentNames));
Console.WriteLine("Expanded: \"{0}\"", rk.GetValue("ExpandValue"));
} //Main
} //Example
Imports Microsoft.Win32
Public Class Example
Public Shared Sub Main()
' Delete and recreate the test key.
Registry.CurrentUser.DeleteSubKey("RegistryValueOptionsExample", False)
Dim rk As RegistryKey = _
Registry.CurrentUser.CreateSubKey("RegistryValueOptionsExample")
' Add a value that contains an environment variable.
rk.SetValue("ExpandValue", "The path is %PATH%", _
RegistryValueKind.ExpandString)
' Retrieve the value, first without expanding the environment
' variable and then expanding it.
Console.WriteLine("Unexpanded: ""{0}""", _
rk.GetValue("ExpandValue", "No Value", _
RegistryValueOptions.DoNotExpandEnvironmentNames))
Console.WriteLine("Expanded: ""{0}""", rk.GetValue("ExpandValue"))
End Sub
End Class
注解
将 DoNotExpandEnvironmentNames 标志与RegistryKey.GetValue(String, Object, RegistryValueOptions)方法重载一起使用。Use the DoNotExpandEnvironmentNames flag with the RegistryKey.GetValue(String, Object, RegistryValueOptions) method overload.