语言

RegistryKey.OpenRemoteBaseKey 方法

定义

打开表示 RegistryKey 远程计算机上请求的密钥的新项,其中包含指定的注册表视图的选项。

重载

名称 说明
OpenRemoteBaseKey(RegistryHive, String)

打开表示远程计算机上的请求密钥的新 RegistryKey 项。

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

打开一个新的注册表项,表示具有指定视图的远程计算机上的请求密钥。

OpenRemoteBaseKey(RegistryHive, String)

Source:
RegistryKey.cs

打开表示远程计算机上的请求密钥的新 RegistryKey 项。

public:
 static Microsoft::Win32::RegistryKey ^ OpenRemoteBaseKey(Microsoft::Win32::RegistryHive hKey, System::String ^ machineName);
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName);
static member OpenRemoteBaseKey : Microsoft.Win32.RegistryHive * string -> Microsoft.Win32.RegistryKey
Public Shared Function OpenRemoteBaseKey (hKey As RegistryHive, machineName As String) As RegistryKey

参数

hKey
RegistryHive

要从枚举打开的 RegistryHive HKEY。

machineName
String

远程计算机。

返回

请求的注册表项。

例外

hKey 无效。

找不到 machineName。

machineName 是 null。

用户没有执行此操作的适当权限。

用户没有必要的注册表权限。

示例

下面的代码示例演示如何在远程计算机上打开注册表项并枚举密钥的值。 远程计算机必须运行远程注册表服务。 在调用程序时,将远程计算机的名称指定为命令行参数。

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

注解

如果 machineName 为 String.Empty,则打开本地计算机注册表。 请求的密钥必须是远程计算机上的根密钥,并由相应的 RegistryHive 值标识。

若要远程打开密钥,服务器和客户端计算机必须运行远程注册表服务并启用远程管理。

另请参阅

适用于

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Source:
RegistryKey.cs

打开一个新的注册表项,表示具有指定视图的远程计算机上的请求密钥。

public:
 static Microsoft::Win32::RegistryKey ^ OpenRemoteBaseKey(Microsoft::Win32::RegistryHive hKey, System::String ^ machineName, Microsoft::Win32::RegistryView view);
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view);
[System.Runtime.InteropServices.ComVisible(false)]
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view);
static member OpenRemoteBaseKey : Microsoft.Win32.RegistryHive * string * Microsoft.Win32.RegistryView -> Microsoft.Win32.RegistryKey
[<System.Runtime.InteropServices.ComVisible(false)>]
static member OpenRemoteBaseKey : Microsoft.Win32.RegistryHive * string * Microsoft.Win32.RegistryView -> Microsoft.Win32.RegistryKey
Public Shared Function OpenRemoteBaseKey (hKey As RegistryHive, machineName As String, view As RegistryView) As RegistryKey

参数

hKey
RegistryHive

要从枚举打开的 RegistryHive HKEY。

machineName
String

远程计算机。

view
RegistryView

要使用的注册表视图。

返回

请求的注册表项。

特性

例外

hKey 或 view 无效。

找不到 machineName。

machineName 是 null。

用户没有必要的注册表权限。

用户没有执行此操作所需的权限。

注解

如果 machineName 为 String.Empty,则打开本地计算机注册表。 请求的密钥必须是远程计算机上的根密钥,并由相应的 RegistryHive 值标识。

若要远程打开密钥,服务器和客户端计算机必须运行远程注册表服务并启用远程管理。

在 64 位版本的 Windows 上,注册表的某些部分单独存储于 32 位和 64 位应用程序。 32 位应用程序有 32 位视图,64 位应用程序的 64 位视图。 如果 view 远程 Registry64 计算机正在运行 32 位操作系统,则返回的 Registry32 密钥将使用视图。

适用于