共用方式為


RegistryKey.OpenRemoteBaseKey 方法

定義

使用指定的登錄檢視選項,開啟遠端電腦上表示要求機碼的新 T:Microsoft.Win32.RegistryKey。

多載

OpenRemoteBaseKey(RegistryHive, String)

開啟遠端電腦上表示要求機碼的新 RegistryKey

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

使用指定的檢視,開啟遠端電腦上表示要求機碼的新登錄機碼。

OpenRemoteBaseKey(RegistryHive, String)

來源:
RegistryKey.cs

開啟遠端電腦上表示要求機碼的新 RegistryKey

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

參數

hKey
RegistryHive

要從 RegistryHive 列舉型別開啟的 HKEY。

machineName
String

遠端電腦。

傳回

要求的登錄機碼。

例外狀況

hKey 無效。

找不到 machineName

machineNamenull

使用者並不具有執行這個作業的適當使用權限。

使用者沒有必要的登錄權限。

範例

下列程式代碼範例示範如何在遠端電腦上開啟登錄機碼,並列舉機碼的值。 遠端電腦必須執行遠端登錄服務。 叫用程式時,將遠端電腦的名稱指定為命令行自變數。

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

備註

如果 machineNameString.Empty,則會開啟本機計算機登錄。 要求的金鑰必須是遠端電腦上的根金鑰,並由適當的 RegistryHive 值識別。

若要從遠端開啟金鑰,伺服器和用戶端電腦都必須執行遠端登錄服務,並啟用遠端管理。

另請參閱

適用於

OpenRemoteBaseKey(RegistryHive, String, RegistryView)

來源:
RegistryKey.cs

使用指定的檢視,開啟遠端電腦上表示要求機碼的新登錄機碼。

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

參數

hKey
RegistryHive

要從 RegistryHive 列舉開啟的 HKEY。

machineName
String

遠端電腦。

view
RegistryView

要使用的登錄檢視。

傳回

要求的登錄機碼。

屬性

例外狀況

hKeyview 無效。

找不到 machineName

machineNamenull

使用者沒有必要的登錄權限。

使用者沒有執行這個作業的必要使用權限。

備註

如果 machineNameString.Empty,則會開啟本機計算機登錄。 要求的金鑰必須是遠端電腦上的根金鑰,並由適當的 RegistryHive 值識別。

若要從遠端開啟金鑰,伺服器和用戶端電腦都必須執行遠端登錄服務,並啟用遠端管理。

在 64 位版本的 Windows 上,登錄的部分會針對 32 位和 64 位應用程式個別儲存。 32 位應用程式有 32 位檢視,64 位應用程式有 64 位檢視。 如果 view 為, Registry64 但遠端計算機正在執行 32 位作業系統,則傳回的 Registry32 密鑰會使用檢視。

適用於