RegistryKey.OpenRemoteBaseKey Metoda

Definice

Otevře nový T:Microsoft.Win32.RegistryKey, který představuje požadovaný klíč na vzdáleném počítači s možností zadaného zobrazení registru.

Přetížení

OpenRemoteBaseKey(RegistryHive, String)

Otevře nový RegistryKey , který představuje požadovaný klíč na vzdáleném počítači.

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Otevře nový klíč registru, který představuje požadovaný klíč na vzdáleném počítači se zadaným zobrazením.

OpenRemoteBaseKey(RegistryHive, String)

Zdroj:
RegistryKey.cs

Otevře nový RegistryKey , který představuje požadovaný klíč na vzdáleném počítači.

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

Parametry

hKey
RegistryHive

Klíč HKEY, který se má otevřít, z výčtu RegistryHive .

machineName
String

Vzdálený počítač.

Návraty

Požadovaný klíč registru.

Výjimky

Formát hKey je neplatný.

machineName nebyl nalezen.

machineName je null.

Uživatel nemá správná oprávnění k provedení této operace.

Uživatel nemá nezbytná oprávnění pro registr.

Příklady

Následující příklad kódu ukazuje, jak otevřít klíč registru na vzdáleném počítači a vytvořit výčet hodnot klíče. Na vzdáleném počítači musí být spuštěná služba vzdáleného registru. Při vyvolání programu zadejte název vzdáleného počítače jako argument příkazového řádku.

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

Poznámky

Registr místního počítače se otevře, pokud machineName je String.Empty. Požadovaný klíč musí být kořenovým klíčem na vzdáleném počítači a je identifikován příslušnou RegistryHive hodnotou.

Aby mohl být klíč otevřen vzdáleně, musí na serveru i na klientském počítači běžet služba vzdáleného registru a musí být povolená vzdálená správa.

Viz také

Platí pro

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Zdroj:
RegistryKey.cs

Otevře nový klíč registru, který představuje požadovaný klíč na vzdáleném počítači se zadaným zobrazením.

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

Parametry

hKey
RegistryHive

Klíč HKEY, který se má otevřít z výčtu RegistryHive .

machineName
String

Vzdálený počítač.

view
RegistryView

Zobrazení registru, které se má použít.

Návraty

Požadovaný klíč registru.

Atributy

Výjimky

hKey nebo view je neplatný.

machineName nebyl nalezen.

machineName je null.

Uživatel nemá nezbytná oprávnění pro registr.

Uživatel nemá požadovaná oprávnění k provedení této operace.

Poznámky

Registr místního počítače se otevře, pokud machineName je String.Empty. Požadovaný klíč musí být kořenovým klíčem na vzdáleném počítači a je identifikován příslušnou RegistryHive hodnotou.

Aby mohl být klíč otevřen vzdáleně, musí na serveru i na klientském počítači běžet služba vzdáleného registru a musí být povolená vzdálená správa.

V 64bitových verzích Systému Windows jsou části registru uloženy samostatně pro 32bitové a 64bitové aplikace. K dispozici je 32bitové zobrazení pro 32bitové aplikace a 64bitové zobrazení pro 64bitové aplikace. Pokud view je Registry64 na vzdáleném počítači spuštěný 32bitový operační systém, bude vrácený klíč používat Registry32 zobrazení.

Platí pro