RegistryHive 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示外部计算机上的顶级节点的可能值。
public enum class RegistryHive
public enum RegistryHive
[System.Serializable]
public enum RegistryHive
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum RegistryHive
type RegistryHive =
[<System.Serializable>]
type RegistryHive =
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type RegistryHive =
Public Enum RegistryHive
- 继承
- 属性
字段
ClassesRoot | -2147483648 | 表示另一个计算机上的 HKEY_CLASSES_ROOT 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
CurrentConfig | -2147483643 | 表示另一个计算机上的 HKEY_CURRENT_CONFIG 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
CurrentUser | -2147483647 | 表示另一个计算机上的 HKEY_CURRENT_USER 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
DynData | -2147483642 | 表示另一个计算机上的 HKEY_DYN_DATA 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
LocalMachine | -2147483646 | 表示另一个计算机上的 HKEY_LOCAL_MACHINE 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
PerformanceData | -2147483644 | 表示另一个计算机上的 HKEY_PERFORMANCE_DATA 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
Users | -2147483645 | 表示另一个计算机上的 HKEY_USERS 基项。 此值可传递给 OpenRemoteBaseKey(RegistryHive, String) 方法,以远程打开此节点。 |
示例
下面的代码示例演示如何在远程计算机上打开注册表项并枚举密钥的值。 远程计算机必须运行远程注册表服务。 在调用程序时,将远程计算机的名称指定为命令行参数。
using namespace System;
using namespace System::IO;
using namespace System::Security::Permissions;
using namespace Microsoft::Win32;
int main( int argc, char *argv[] )
{
RegistryKey ^ environmentKey;
// Check that an argument was specified when the
// program was invoked.
if ( argc == 1 )
{
Console::WriteLine( "Error: The name of the remote computer "
"must be specified as input on the command line." );
return -1;
}
try
{
// Open HKEY_CURRENT_USER\Environment on a remote computer.
environmentKey = RegistryKey::OpenRemoteBaseKey( RegistryHive::CurrentUser, gcnew String(argv[ 1 ]) )->OpenSubKey( "Environment" );
}
catch ( IOException^ e )
{
Console::WriteLine( "{0}: {1}", e->GetType()->Name, e->Message );
return -1;
}
// Print the values.
Console::WriteLine( "\nThere are {0} values for {1}.", environmentKey->ValueCount.ToString(), environmentKey->Name );
array<String^>^valueNames = environmentKey->GetValueNames();
for ( int i = 0; i < environmentKey->ValueCount; i++ )
{
Console::WriteLine( "{0,-20}: {1}", valueNames[ i ], environmentKey->GetValue( valueNames[ i ] )->ToString() );
}
// Close the registry key.
environmentKey->Close();
}
using System;
using System.IO;
using System.Security.Permissions;
using Microsoft.Win32;
class RemoteKey
{
static void Main(string[] args)
{
RegistryKey environmentKey;
string remoteName;
// Check that an argument was specified when the
// program was invoked.
if(args.Length == 0)
{
Console.WriteLine("Error: The name of the remote " +
"computer must be specified when the program is " +
"invoked.");
return;
}
else
{
remoteName = args[0];
}
try
{
// Open HKEY_CURRENT_USER\Environment
// on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey(
RegistryHive.CurrentUser, remoteName).OpenSubKey(
"Environment");
}
catch(IOException e)
{
Console.WriteLine("{0}: {1}",
e.GetType().Name, e.Message);
return;
}
// Print the values.
Console.WriteLine("\nThere are {0} values for {1}.",
environmentKey.ValueCount.ToString(),
environmentKey.Name);
foreach(string valueName in environmentKey.GetValueNames())
{
Console.WriteLine("{0,-20}: {1}", valueName,
environmentKey.GetValue(valueName).ToString());
}
// Close the registry key.
environmentKey.Close();
}
}
Imports System.IO
Imports System.Security.Permissions
Imports Microsoft.Win32
Public Class RemoteKey
Shared Sub Main(commandLineArgs As String())
Dim environmentKey As RegistryKey
' Check that an argument was specified when the
' program was invoked.
If commandLineArgs.Length = 0 Then
Console.WriteLine("Error: The name of the remote " & _
"computer must be specified as input on the " & _
"command line.")
Return
End If
Try
' Open HKEY_CURRENT_USER\Environment on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.CurrentUser, _
commandLineArgs(0)).OpenSubKey("Environment")
Catch ex As IOException
Console.WriteLine("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
' Print the values.
Console.WriteLine("\nThere are {0} values For {1}.", _
environmentKey.ValueCount.ToString(), environmentKey.Name)
For Each valueName As String In environmentKey.GetValueNames()
Console.WriteLine("{0,-20}: {1}", valueName, _
environmentKey.GetValue(valueName).ToString())
Next
' Close the registry key.
environmentKey.Close()
End Sub
End Class
注解
RegistryHive
方法使用 OpenRemoteBaseKey 值来表示外部 (远程) 计算机上的所请求密钥的顶级节点。 可以使用 OpenRemoteBaseKey 方法打开的节点必须是这些顶级 的其中一个。RegistryKeys
只要用户具有适当的权限,即可使用 中的 RegistryKey方法进一步访问标识的节点的子项。