RegistryKey.OpenRemoteBaseKey メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Public Shared Function OpenRemoteBaseKey ( _ hKey As RegistryHive, _ machineName As String _ ) As RegistryKey
Dim hKey As RegistryHive Dim machineName As String Dim returnValue As RegistryKey returnValue = RegistryKey.OpenRemoteBaseKey(hKey, machineName)
public static function OpenRemoteBaseKey ( hKey : RegistryHive, machineName : String ) : RegistryKey
戻り値
要求された RegistryKey。


machineName が String.Empty の場合、ローカル コンピュータのレジストリが開かれます。要求したキーはリモート コンピュータのルート キーである必要があります。このキーは、適切な RegistryHive 値により識別されます。
キーをリモート操作で開くには、サーバーとクライアントの両方のコンピュータでリモート レジストリ サービスを実行しており、リモート管理機能が有効である必要があります。

リモート コンピュータでレジストリ キーを開き、そのキーの値を列挙する方法を次のコード例に示します。リモート コンピュータは、リモート レジストリ サービスを実行している必要があります。プログラムを呼び出すときにリモート コンピュータ名をコマンドライン引数として指定します。
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


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- RegistryKey.OpenRemoteBaseKey メソッドのページへのリンク