This documentation is archived and is not being maintained.

Registry.LocalMachine Field

Contains the configuration data for the local machine. This field reads the Windows registry base key HKEY_LOCAL_MACHINE.

Namespace:  Microsoft.Win32
Assembly:  mscorlib (in mscorlib.dll)

public static readonly RegistryKey LocalMachine

LocalMachine contains five keys:


Describes the physical hardware in the computer, the way device drivers use that hardware, and mappings and related data that link kernel-mode drivers with user-mode code. All data in this key is recreated each time the system is started. The Description subkey describes the actual computer hardware. The DeviceMap subkey contains miscellaneous data in formats specific to particular classes of drivers. The ResourceMap subkey describes which device drivers claim which hardware resources. The Windows NT Diagnostics program (Winmsdp.exe) can report on its contents in an easy-to-read form.


The directory services database of security information for user and group accounts, and for the domains in Windows 2000 Server (SAM is the Security Account Manager, known as the directory services database).


Contains the local security policy, such as specific user rights. This key is used only by the Windows 2000 security subsystem.


The per-computer software database. This key contains data about software installed on the local computer, along with various items of miscellaneous configuration data.


Controls system startup, device driver loading, Windows 2000 services, and operating system behavior.

By convention, if similar data exists under CurrentUser and under LocalMachine, the data in CurrentUser takes precedence. However, values in this key can also extend (rather than replace) data in Registry.LocalMachine. Also, some items (such as device driver loading entries) are meaningless if they occur outside of Registry.LocalMachine.

The following example demonstrates how to retrieve the subkeys of this key, and prints their names to the screen. Use the OpenSubKey method to create an instance of the particular subkey of interest. You can then use other operations in RegistryKey to manipulate that key.

using System;
using Microsoft.Win32;

class Reg {
    public static void Main() {

        // Create a RegistryKey, which will access the HKEY_LOCAL_MACHINE
        // key in the registry of this machine.
         RegistryKey rk = Registry.LocalMachine;

        // Print out the keys.

    static void PrintKeys(RegistryKey rkey) {

        // Retrieve all the subkeys for the specified key.
        String [] names = rkey.GetSubKeyNames();

        int icount = 0;

        Console.WriteLine("Subkeys of " + rkey.Name);

        // Print the contents of the array to the console.
        foreach (String s in names) {

            // The following code puts a limit on the number
            // of keys displayed.  Comment it out to print the
            // complete list.
            if (icount >= 10)

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.