Share via


RegistryKey.OpenRemoteBaseKey Metode

Definisi

Membuka T:Microsoft.Win32.RegistryKey baru yang mewakili kunci yang diminta pada komputer jarak jauh, dengan opsi tampilan registri yang ditentukan.

Overload

OpenRemoteBaseKey(RegistryHive, String)

Membuka baru RegistryKey yang mewakili kunci yang diminta pada komputer jarak jauh.

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Membuka kunci registri baru yang mewakili kunci yang diminta pada komputer jarak jauh dengan tampilan yang ditentukan.

OpenRemoteBaseKey(RegistryHive, String)

Sumber:
RegistryKey.cs

Membuka baru RegistryKey yang mewakili kunci yang diminta pada komputer jarak jauh.

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

Parameter

hKey
RegistryHive

HKEY yang akan dibuka, dari RegistryHive enumerasi.

machineName
String

Mesin jarak jauh.

Mengembalikan

Kunci registri yang diminta.

Pengecualian

hKey tidak valid.

machineName tidak ditemukan.

machineNameadalah null.

Pengguna tidak memiliki izin yang tepat untuk melakukan operasi ini.

Pengguna tidak memiliki hak registri yang diperlukan.

Contoh

Contoh kode berikut menunjukkan cara membuka kunci registri di komputer jarak jauh dan menghitung nilai kunci. Komputer jarak jauh harus menjalankan layanan registri jarak jauh. Tentukan nama komputer jarak jauh sebagai argumen baris perintah saat memanggil 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 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

Keterangan

Registri komputer lokal dibuka jika machineName adalah String.Empty. Kunci yang diminta harus merupakan kunci akar pada komputer jarak jauh, dan diidentifikasi oleh nilai yang sesuai RegistryHive .

Agar kunci dibuka dari jarak jauh, komputer server dan klien harus menjalankan layanan registri jarak jauh, dan mengaktifkan administrasi jarak jauh.

Lihat juga

Berlaku untuk

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Sumber:
RegistryKey.cs

Membuka kunci registri baru yang mewakili kunci yang diminta pada komputer jarak jauh dengan tampilan yang ditentukan.

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

Parameter

hKey
RegistryHive

HKEY yang akan dibuka dari RegistryHive enumerasi.

machineName
String

Mesin jarak jauh.

view
RegistryView

Tampilan registri yang akan digunakan.

Mengembalikan

Kunci registri yang diminta.

Atribut

Pengecualian

hKey atau view tidak valid.

machineName tidak ditemukan.

machineNameadalah null.

Pengguna tidak memiliki hak registri yang diperlukan.

Pengguna tidak memiliki izin yang diperlukan untuk melakukan operasi ini.

Keterangan

Registri komputer lokal dibuka jika machineName adalah String.Empty. Kunci yang diminta harus merupakan kunci akar pada komputer jarak jauh, dan diidentifikasi oleh nilai yang sesuai RegistryHive .

Agar kunci dibuka dari jarak jauh, komputer server dan klien harus menjalankan layanan registri jarak jauh, dan mengaktifkan administrasi jarak jauh.

Pada Windows versi 64-bit, bagian registri disimpan secara terpisah untuk aplikasi 32-bit dan 64-bit. Ada tampilan 32-bit untuk aplikasi 32-bit dan tampilan 64-bit untuk aplikasi 64-bit. Jika view adalah Registry64 tetapi komputer jarak jauh menjalankan sistem operasi 32-bit, kunci yang dikembalikan akan menggunakan Registry32 tampilan .

Berlaku untuk