Freigeben über


RegistryKey.OpenRemoteBaseKey-Methode

Öffnet einen neuen RegistryKey, der den angeforderten Schlüssel für einen Remotecomputer darstellt.

Namespace: Microsoft.Win32
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function OpenRemoteBaseKey ( _
    hKey As RegistryHive, _
    machineName As String _
) As RegistryKey
'Usage
Dim hKey As RegistryHive
Dim machineName As String
Dim returnValue As RegistryKey

returnValue = RegistryKey.OpenRemoteBaseKey(hKey, machineName)
public static RegistryKey OpenRemoteBaseKey (
    RegistryHive hKey,
    string machineName
)
public:
static RegistryKey^ OpenRemoteBaseKey (
    RegistryHive hKey, 
    String^ machineName
)
public static RegistryKey OpenRemoteBaseKey (
    RegistryHive hKey, 
    String machineName
)
public static function OpenRemoteBaseKey (
    hKey : RegistryHive, 
    machineName : String
) : RegistryKey

Parameter

  • hKey
    Der zu öffnende HKEY aus der RegistryHive-Enumeration.
  • machineName
    Der Remotecomputer.

Rückgabewert

Der angeforderte RegistryKey.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Der hKey ist ungültig.

IOException

machineName wurde nicht gefunden.

ArgumentNullException

machineName ist NULL (Nothing in Visual Basic).

SecurityException

Der Benutzer verfügt nicht über ausreichende Berechtigungen zum Ausführen dieser Aktion.

UnauthorizedAccessException

Der Benutzer verfügt nicht über die notwendigen Registrierungsrechte.

Hinweise

Die lokale Computerregistrierung wird geöffnet, wenn machineName gleich String.Empty ist. Der angeforderte Schlüssel muss ein Stammschlüssel auf dem Remotecomputer sein. Er wird durch den entsprechenden RegistryHive-Wert bestimmt.

Ein Schlüssel kann nur dann remote geöffnet werden, wenn auf beiden Computern (Server und Client) der Remoteregistrierungsdienst ausgeführt wird und die Remoteverwaltung aktiviert ist.

Beispiel

Das folgende Codebeispiel veranschaulicht das Öffnen eines Registrierungsschlüssels auf einem Remotecomputer und das Auflisten der Werte des Schlüssels. Auf dem Remotecomputer muss der Remoteregistrierungsdienst ausgeführt werden. Geben Sie den Namen des Remotecomputers beim Aufrufen des Programms als Befehlszeilenargument an.

Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Security.Permissions
Imports Microsoft.Win32

<Assembly: RegistryPermissionAttribute( _
    SecurityAction.RequestMinimum, _
    Read := "HKEY_CURRENT_USER\Environment")>
<Assembly: SecurityPermissionAttribute( _
    SecurityAction.RequestMinimum, UnmanagedCode := True)>

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
using System;
using System.IO;
using System.Security.Permissions;
using Microsoft.Win32;

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
    Read = @"HKEY_CURRENT_USER\Environment")]
[assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum,
    UnmanagedCode = true)]

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();
    }
}
using namespace System;
using namespace System::IO;
using namespace System::Security::Permissions;
using namespace Microsoft::Win32;

[assembly:RegistryPermissionAttribute(SecurityAction::RequestMinimum,
Read="HKEY_CURRENT_USER\\Environment")];
[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum,
UnmanagedCode=true)];
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();
}
import System.*;
import System.IO.*;
import System.Security.Permissions.*;
import Microsoft.Win32.*;

/** @assembly RegistryPermissionAttribute(SecurityAction.RequestMinimum, 
    Read = "HKEY_CURRENT_USER\\Environment")
 */
/** @assembly SecurityPermissionAttribute(SecurityAction.RequestMinimum, 
    UnmanagedCode = true)
 */
class RemoteKey
{
    public static void main(String[] args)
    {
        RegistryKey environmentKey;
        String remoteName;
        // Check that an argument was specified when the 
        // program was invoked.
        if (args.get_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().get_Name(), 
                e.get_Message());
            return;
        }

        // Print the values.
        Console.WriteLine("\nThere are {0} values for {1}.", 
            Convert.ToString(environmentKey.get_ValueCount()), 
            environmentKey.get_Name());
        for (int iCtr = 0; iCtr < environmentKey.GetValueNames().get_Length();
            iCtr++) {
            String valueName = (String)environmentKey.GetValueNames().
                get_Item(iCtr);
            Console.WriteLine("{0,-20}: {1}", valueName, 
                environmentKey.GetValue(valueName).ToString());
        }

        // Close the registry key.
        environmentKey.Close();
    } //main
} //RemoteKey

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

RegistryKey-Klasse
RegistryKey-Member
Microsoft.Win32-Namespace
RegistryHive-Enumeration
OpenSubKey