RegistryHive Enumeration
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Enumeration RegistryHive 'Usage Dim instance As RegistryHive
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public enum RegistryHive
SerializableAttribute ComVisibleAttribute(true) public enum RegistryHive
| Member name | Description | |
|---|---|---|
| ClassesRoot | Represents the HKEY_CLASSES_ROOT base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. | |
| CurrentConfig | Represents the HKEY_CURRENT_CONFIG base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. | |
| CurrentUser | Represents the HKEY_CURRENT_USER base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. | |
| DynData | Represents the HKEY_DYN_DATA base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. | |
| LocalMachine | Represents the HKEY_LOCAL_MACHINE base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. | |
| PerformanceData | Represents the HKEY_PERFORMANCE_DATA base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. | |
| Users | Represents the HKEY_USERS base key on another computer. This value can be passed to the OpenRemoteBaseKey method, to open this node remotely. |
RegistryHive values are used by the OpenRemoteBaseKey method to represent the top-level node of a requested key on a foreign (remote) machine. The node that can be opened with the OpenRemoteBaseKey method must be one of these top-level RegistryKeys. Further access to the subkeys of the identified node is available using using methods in RegistryKey, so long as the the user has appropriate permission.
The following code example shows how to open a registry key on a remote computer and enumerate the values of the key. The remote computer must be running the remote registry service. Specify the name of the remote computer as a command-line argument when invoking the program.
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
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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.