RegistryKey.OpenRemoteBaseKey Metoda

Definicja

Otwiera nowy klucz T:Microsoft.Win32.RegistryKey reprezentujący żądany klucz na maszynie zdalnej z opcją określonego widoku rejestru.

Przeciążenia

OpenRemoteBaseKey(RegistryHive, String)

Otwiera nowy RegistryKey , który reprezentuje żądany klucz na maszynie zdalnej.

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Otwiera nowy klucz rejestru reprezentujący żądany klucz na maszynie zdalnej z określonym widokiem.

OpenRemoteBaseKey(RegistryHive, String)

Źródło:
RegistryKey.cs

Otwiera nowy RegistryKey , który reprezentuje żądany klucz na maszynie zdalnej.

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

Klucz HKEY do otwarcia z wyliczenia RegistryHive .

machineName
String

Maszyna zdalna.

Zwraca

Żądany klucz rejestru.

Wyjątki

Nazwa hKey jest niepoprawna.

machineName nie można odnaleźć.

machineName to null.

Użytkownik nie ma odpowiednich uprawnień do wykonania tej operacji.

Użytkownik nie posiada niezbędnych praw wobec rejestru.

Przykłady

Poniższy przykład kodu pokazuje, jak otworzyć klucz rejestru na komputerze zdalnym i wyliczyć wartości klucza. Komputer zdalny musi mieć uruchomioną usługę rejestru zdalnego. Określ nazwę komputera zdalnego jako argument wiersza polecenia podczas wywoływania programu.

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

Uwagi

Rejestr komputera lokalnego jest otwierany, jeśli machineName jest to String.Empty. Żądany klucz musi być kluczem głównym na maszynie zdalnej i jest identyfikowany przez odpowiednią RegistryHive wartość.

Aby klucz był otwierany zdalnie, zarówno serwer, jak i komputery klienckie muszą być uruchomione zdalnej usługi rejestru i mieć włączoną zdalną administrację.

Zobacz też

Dotyczy

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Źródło:
RegistryKey.cs

Otwiera nowy klucz rejestru reprezentujący żądany klucz na maszynie zdalnej z określonym widokiem.

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

Klucz HKEY do otwarcia z wyliczenia RegistryHive .

machineName
String

Maszyna zdalna.

view
RegistryView

Widok rejestru do użycia.

Zwraca

Żądany klucz rejestru.

Atrybuty

Wyjątki

hKey lub view jest nieprawidłowy.

machineName nie można odnaleźć.

machineName to null.

Użytkownik nie posiada niezbędnych praw wobec rejestru.

Użytkownik nie ma wymaganych uprawnień do wykonania tej operacji.

Uwagi

Rejestr komputera lokalnego jest otwierany, jeśli machineName jest to String.Empty. Żądany klucz musi być kluczem głównym na maszynie zdalnej i jest identyfikowany przez odpowiednią RegistryHive wartość.

Aby klucz był otwierany zdalnie, zarówno serwer, jak i komputery klienckie muszą być uruchomione zdalnej usługi rejestru i mieć włączoną zdalną administrację.

W 64-bitowych wersjach systemu Windows fragmenty rejestru są przechowywane oddzielnie dla aplikacji 32-bitowych i 64-bitowych. Istnieje widok 32-bitowy dla aplikacji 32-bitowych i 64-bitowego widoku dla aplikacji 64-bitowych. Jeśli view maszyna Registry64 zdalna korzysta z 32-bitowego systemu operacyjnego, zwrócony klucz będzie używać Registry32 widoku.

Dotyczy