RegistryKey.OpenRemoteBaseKey RegistryKey.OpenRemoteBaseKey RegistryKey.OpenRemoteBaseKey RegistryKey.OpenRemoteBaseKey Method

Definición

Abre un nuevo objeto T:Microsoft.Win32.RegistryKey que representa la clave solicitada en un equipo remoto, con la opción de vista del Registro especificada.Opens a new T:Microsoft.Win32.RegistryKey that represents the requested key on a remote machine, with the option of specified registry view.

Sobrecargas

OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String)

Abre un nuevo RegistryKey que representa la clave solicitada en un equipo remoto.Opens a new RegistryKey that represents the requested key on a remote machine.

OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Abre una nueva clave del Registro que representa la clave solicitada en un equipo remoto con la vista especificada.Opens a new registry key that represents the requested key on a remote machine with the specified view.

OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String)

Abre un nuevo RegistryKey que representa la clave solicitada en un equipo remoto.Opens a new RegistryKey that represents the requested key on a remote machine.

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

Parámetros

hKey
RegistryHive RegistryHive RegistryHive RegistryHive

HKEY que se va a abrir, de la enumeración RegistryHive.The HKEY to open, from the RegistryHive enumeration.

machineName
String String String String

Equipo remoto.The remote machine.

Devoluciones

Clave del Registro solicitada.The requested registry key.

Excepciones

No se ha encontrado machineName.machineName is not found.

El valor de machineName es null.machineName is null.

El usuario no tiene los permisos adecuados para realizar esta operación.The user does not have the proper permissions to perform this operation.

El usuario no tiene los derechos necesarios en el registro.The user does not have the necessary registry rights.

Ejemplos

El ejemplo de código siguiente muestra cómo abrir una clave del registro en un equipo remoto y enumerar los valores de la clave.The following code example shows how to open a registry key on a remote computer and enumerate the values of the key. El equipo remoto debe estar ejecutando el servicio de registro remoto.The remote computer must be running the remote registry service. Especifique el nombre del equipo remoto como un argumento de línea de comandos al invocar el programa.Specify the name of the remote computer as a command-line argument when invoking the program.

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 Microsoft.VisualBasic
Imports System
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

Comentarios

Se abre el registro del equipo local si machineName es String.Empty.The local machine registry is opened if machineName is String.Empty. La clave solicitada debe ser una clave de raíz en el equipo remoto y se identifica mediante el correspondiente RegistryHive valor.The requested key must be a root key on the remote machine, and is identified by the appropriate RegistryHive value.

En orden para que una clave abiertos de forma remota, equipos del cliente y servidor deben estar ejecutando el servicio Registro remoto y tener habilitada la administración remota.In order for a key to be opened remotely, both the server and client machines must be running the remote registry service, and have remote administration enabled.

Seguridad

SecurityPermission
para que poder acceder a la clave de registro especificado, si es una clave remota.for the ability to access the specified registry key if it is a remote key. Enumeración asociada: UnmanagedCodeAssociated enumeration: UnmanagedCode

Consulte también:

OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Abre una nueva clave del Registro que representa la clave solicitada en un equipo remoto con la vista especificada.Opens a new registry key that represents the requested key on a remote machine with the specified view.

public:
 static Microsoft::Win32::RegistryKey ^ OpenRemoteBaseKey(Microsoft::Win32::RegistryHive hKey, System::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
Public Shared Function OpenRemoteBaseKey (hKey As RegistryHive, machineName As String, view As RegistryView) As RegistryKey

Parámetros

hKey
RegistryHive RegistryHive RegistryHive RegistryHive

HKEY que se va a abrir desde la enumeración RegistryHive.The HKEY to open from the RegistryHive enumeration.

machineName
String String String String

Equipo remoto.The remote machine.

view
RegistryView RegistryView RegistryView RegistryView

Vista del Registro que se va a usar.The registry view to use.

Devoluciones

Clave del Registro solicitada.The requested registry key.

Excepciones

hKey o view no es válido.hKey or view is invalid.

No se ha encontrado machineName.machineName is not found.

El valor de machineName es null.machineName is null.

El usuario no tiene los derechos necesarios en el registro.The user does not have the necessary registry rights.

El usuario no tiene los permisos necesarios para realizar esta operación.The user does not have the required permissions to perform this operation.

Comentarios

Se abre el registro del equipo local si machineName es String.Empty.The local machine registry is opened if machineName is String.Empty. La clave solicitada debe ser una clave de raíz en el equipo remoto y se identifica mediante el correspondiente RegistryHive valor.The requested key must be a root key on the remote machine, and is identified by the appropriate RegistryHive value.

En orden para que una clave abiertos de forma remota, equipos del cliente y servidor deben estar ejecutando el servicio Registro remoto y tener habilitada la administración remota.In order for a key to be opened remotely, both the server and client machines must be running the remote registry service, and have remote administration enabled.

En las versiones de 64 bits de Windows, las partes del registro se almacenan por separado para las aplicaciones de 32 bits y 64 bits.On the 64-bit versions of Windows, portions of the registry are stored separately for 32-bit and 64-bit applications. Hay una vista de 32 bits para las aplicaciones de 32 bits y una vista de 64 bits para las aplicaciones de 64 bits.There is a 32-bit view for 32-bit applications and a 64-bit view for 64-bit applications. Si view es Registry64 pero el equipo remoto se está ejecutando un sistema operativo de 32 bits, la clave devuelta utilizará la Registry32 vista.If view is Registry64 but the remote machine is running a 32-bit operating system, the returned key will use the Registry32 view.

Se aplica a