Op Englesch liesen Editéieren

Deelen iwwer


RegistryHive Enum

Definition

Represents the possible values for a top-level node on a foreign machine.

C#
public enum RegistryHive
C#
[System.Serializable]
public enum RegistryHive
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum RegistryHive
Inheritance
RegistryHive
Attributes

Fields

Name Value Description
ClassesRoot -2147483648

Represents the HKEY_CLASSES_ROOT base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

CurrentUser -2147483647

Represents the HKEY_CURRENT_USER base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

LocalMachine -2147483646

Represents the HKEY_LOCAL_MACHINE base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

Users -2147483645

Represents the HKEY_USERS base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

PerformanceData -2147483644

Represents the HKEY_PERFORMANCE_DATA base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

CurrentConfig -2147483643

Represents the HKEY_CURRENT_CONFIG base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

DynData -2147483642

Represents the HKEY_DYN_DATA base key on another computer. This value can be passed to the OpenRemoteBaseKey(RegistryHive, String) method, to open this node remotely.

Examples

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.

C#
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();
    }
}

Remarks

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 methods in RegistryKey, so long as the user has appropriate permission.

Applies to

Produkt Versiounen
.NET Core 1.0, Core 1.1, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5

See also