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)
LocalMachine contains five keys:
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. PrintKeys(rk); } 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); Console.WriteLine("-----------------------------------------------"); // Print the contents of the array to the console. foreach (String s in names) { Console.WriteLine(s); // The following code puts a limit on the number // of keys displayed. Comment it out to print the // complete list. icount++; if (icount >= 10) break; } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.