RegistryHive 列挙体
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Enumeration RegistryHive

メンバ名 | 説明 | |
---|---|---|
ClassesRoot | 別のコンピュータの HKEY_CLASSES_ROOT 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 | |
CurrentConfig | 別のコンピュータの HKEY_CURRENT_CONFIG 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 | |
CurrentUser | 別のコンピュータの HKEY_CURRENT_USER 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 | |
DynData | 別のコンピュータの HKEY_DYN_DATA 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 | |
LocalMachine | 別のコンピュータの HKEY_LOCAL_MACHINE 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 | |
PerformanceData | 別のコンピュータの HKEY_PERFORMANCE_DATA 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 | |
Users | 別のコンピュータの HKEY_USERS 基本キーを表します。この値を OpenRemoteBaseKey メソッドに渡すと、このノードをリモートから開くことができます。 |

RegistryHive の値は、OpenRemoteBaseKey メソッドにより使用され、外部 (リモート) コンピュータ上の要求されたキーの最上位ノードを表します。OpenRemoteBaseKey メソッドを使用してオープンできるノードは、最上位レベル RegistryKeys のいずれかである必要があります。ユーザーに適切なアクセス許可が設定されている場合は、RegistryKey のメソッドを使用して、識別されたノードのサブキーにアクセスできます。

リモート コンピュータでレジストリ キーを開き、そのキーの値を列挙する方法を次のコード例に示します。リモート コンピュータは、リモート レジストリ サービスを実行している必要があります。プログラムを呼び出すときにリモート コンピュータ名をコマンドライン引数として指定します。
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 Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- RegistryHive 列挙体のページへのリンク