mscorlib 1.0.5000.0 2.0.0.0 4.0.0.0 System.Object System.Runtime.InteropServices.ComVisible(true)

This class provides the set of standard root keys found in the registry on machines running Windows. The registry is a storage facility for information about applications, users, and default system settings. For example, applications can use the registry for storing information that needs to be preserved after the application is closed, and access that same information when the application is reloaded. For instance, you can store color preferences, screen locations, or the size of the window. You can control this data for each user by storing the information in a different location in the registry.

The base, or root instances that are exposed by the Registry class delineate the basic storage mechanism for subkeys and values in the registry. All keys are read-only because the registry depends on their existence. The keys exposed by Registry are:

Stores information about user preferences.

Stores configuration information for the local machine.

Stores information about types (and classes) and their properties.

Stores information about the default user configuration.

Stores performance information for software components.

Stores non-user-specific hardware information.

Stores dynamic data.

Once you have identified the root key under which you want to store/retrieve information from the registry, you can use the class to add or remove subkeys, and manipulate the values for a given key.

Hardware devices can place information in the registry automatically using the Plug and Play interface. Software for installing device drivers can place information in the registry by writing to standard APIs.

## Static Methods for Getting and Setting Values

In the .NET Framework version 2.0, the class also contains static and methods for setting and retrieving values from registry keys. These methods open and close registry keys each time they are used, so they do not perform as well as analogous methods in the class, when you access a large number of values.

The class also provides methods that allow you to set Windows access control security for registry keys, to test the data type of a value before retrieving it, and to delete keys.

Provides objects that represent the root keys in the Windows registry, and static methods to access key/value pairs.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.RegistryKey

  Both conventional applications and OLE applications use data that is stored under this key. This key also provides backward compatibility with the Windows 3.1 registration database by storing information for DDE and OLE support. File viewers and user interface extensions store their OLE class identifiers in this key, and processing servers are registered in this key.

  Defines the types (or classes) of documents and the properties associated with those types. This field reads the Windows registry base key HKEY_CLASSES_ROOT.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.RegistryKey

  This member is mapped to a subkey within .

  An example of using this member is an application that stores a different server name for its data depending on whether the system is attached to a network.

  Contains configuration information pertaining to the hardware that is not specific to the user. This field reads the Windows registry base key HKEY_CURRENT_CONFIG.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.RegistryKey

  Information stored in this key includes the settings of environment variables and data about program groups, colors, printers, network connections, and application preferences. This key makes it easier to establish the current user's settings. In this key, software vendors store the current user-specific preferences to be used within their applications. Microsoft, for example, creates the HKEY_CURRENT_USER\Software\Microsoft key for its applications to use, with each application creating its own subkey under the Microsoft key.

  Contains information about the current user preferences. This field reads the Windows registry base key HKEY_CURRENT_USER

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("Use PerformanceData instead")
  Microsoft.Win32.RegistryKey

  The Windows 98/Windows Me registry supports both static data (which is stored on disk in the registry) and dynamic data (which changes frequently, such as performance statistics). This dynamic data area is the mechanism that allows Virtual Device Drivers (VxDs) to provide real-time data to Win32 applications that can run remotely as well as locally. It also allows the system monitor to provide performance statistics on remote Windows 98/Windows Me systems.

  VxDs are not limited to performance data. They can provide any data they want to pass from Ring 0 to Ring 3 efficiently without monopolizing the CPU. The registry supports dynamic data by storing a pointer to a function that returns a value (or many values). When a Registry call queries values associated with a dynamic key, that function is called to return the desired value or values.

  Dynamic keys were introduced in Microsoft Windows 95 to handle dynamic Registry data. They are supported only in Windows 98/Windows Me.

  Contains dynamic registry data. This field reads the Windows registry base key HKEY_DYN_DATA.

- Method
  2.0.0.0
  4.0.0.0
  System.Object `` `` ``

  The string is not case-sensitive.

  A registry key can contain one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To retrieve this unnamed value, specify either null or the empty string ("") for .

  Valid root names are HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG, and HKEY_DYN_DATA. For example, in Visual Basic the string "HKEY_CURRENT_USER\MyTestKey" accesses key/value pairs for the subkey "MyTestKey" in the HKEY_CURRENT_USER root.

  When the method retrieves expandable string values (), it expands environment strings using data from the local environment. If a value containing expandable references to environment variables has been stored as a string (), rather than as an expandable string (), does not expand it. You can expand such a string after it has been retrieved by calling the method.

  The recommended way to retrieve data from HKEY_PERFORMANCE_DATA is to use the class rather than the method.

  The and methods open and close registry keys each time they are used, so they do not perform as well as the methods of the class if you access a large number of values.

  also provides methods that allow you to add an access control list (ACL) to a registry key, to test the data type of a value before retrieving it, and to delete keys.

  Retrieves the value associated with the specified name, in the specified registry key. If the name is not found in the specified key, returns a default value that you provide, or null if the specified key does not exist.

  null if the subkey specified by does not exist; otherwise, the value associated with , or if is not found.

  The full registry path of the key, beginning with a valid registry root, such as "HKEY_CURRENT_USER". The name of the name/value pair. The value to return if does not exist.
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.RegistryKey

  LocalMachine contains five keys:

  Hardware

  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.

  SAM

  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).

  Security

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

  Software

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

  System

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

  By convention, if similar data exists under and under , the data in 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.

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

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.RegistryKey

  Each software component creates keys for its objects, counters when it is installed, and writes counter data while it is executing. You can access this data as you would access any other registry data, using the functions.

  Although you use the registry to collect performance data, the data is not stored in the registry database. Instead, accessing the registry with this key causes the system to collect the data from the appropriate system object managers.

  To obtain performance data from the local system, use the method, with the Registry.PerformanceData key. The first call opens the key (you do not need to explicitly open the key first). However, be sure to use the method to close the handle to the key when you are finished obtaining performance data. The user cannot install or remove a software component while its performance data is in use.

  To obtain performance data from a remote system, you must use the method, with the computer name of the remote system and the Registry.PerformanceData key. This call retrieves a key representing the performance data for the remote system. To retrieve the data, call using this key, rather than the Registry.PerformanceData key.

  On Windows Server 2003, a user must at least belong to the Performance Monitor Users group in order to access subkeys of this base key.

  Contains performance information for software components. This field reads the Windows registry base key HKEY_PERFORMANCE_DATA.

- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  Starting with the net_v40_long, the parameter is no longer restricted to a maximum of 255 characters; however, the parameter continues to have the 255-character restriction.

  Because many values can be stored in each key in the registry, you must use the parameter to specify the particular value you want to set.

  A registry key can contain one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To set this unnamed value, specify either null or the empty string ("") for .

  If does not exist in the key, it is created and the associated value is set to .

  If specifies a subkey that does not exist, the subkey is created in the specified root. For example, in Visual Basic the string "HKEY_CURRENT_USER\MyTestKey" creates the subkey "MyTestKey" in the HKEY_CURRENT_USER root. The string "HKEY_CURRENT_USER\MyTestKey\Key2\Key3" creates the nested subkeys "MyTestKey", "MyTestKey\Key2", and "MyTestKey\Key2\Key3".

  Valid root names include HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG, and HKEY_DYN_DATA.

  The method opens a registry key, sets the value, and closes the key each time it is called. If you need to modify a large number of values, the method might provide better performance. The class also provides methods that allow you to add an access control list (ACL) to a registry key, to test the data type of a value before retrieving it, and to delete keys.

  This overload of stores 64-bit integers as strings (). To store 64-bit numbers as values, use the method overload.

  This overload of stores all string values as objects, even if they contain expandable references to environment variables. To save string values as expandable strings (), use the method overload.

  This overload is equivalent to calling the method overload with .

  On Windows 98 and Windows Millennium Edition (Windows Me), the registry is not Unicode, and not all Unicode characters are valid for all code pages. A Unicode character that is invalid for the current code page is replaced by the best available match. No exception is thrown.

  Sets the specified name/value pair on the specified registry key. If the specified key does not exist, it is created.

  The full registry path of the key, beginning with a valid registry root, such as "HKEY_CURRENT_USER". The name of the name/value pair. The value to be stored.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` ``

  Starting with the net_v40_long, the parameter is no longer restricted to a maximum of 255 characters; however, the parameter continues have the 255-character restriction.

  Because many values can be stored in each key in the registry, you must use the parameter to specify the particular value you want to set.

  A registry key can contain one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To set this unnamed value, specify either null or the empty string ("") for .

  If does not exist in the key, it is created and the associated value is set to .

  If specifies a subkey that does not exist, the subkey is created in the specified root. For example, in Visual Basic the string "HKEY_CURRENT_USER\MyTestKey" creates the subkey "MyTestKey" in the HKEY_CURRENT_USER root. The string "HKEY_CURRENT_USER\MyTestKey\Key2\Key3" creates the nested subkeys "MyTestKey", "MyTestKey\Key2", and "MyTestKey\Key2\Key3".

  Valid root names include HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG, and HKEY_DYN_DATA.

  The method opens a registry key, sets the value, and closes the key each time it is called. If you need to modify a large number of values, the method might provide better performance. The class also provides methods that allow you to add an access control list (ACL) to a registry key, to test the data type of a value before retrieving it, and to delete keys.

  If the type of the specified does not match the specified , and the data cannot be converted, is thrown. For example, you can store a as a , but only if its value is less than the maximum value of a . You cannot store a single string value as a .

  If boxed values are passed for or , the conversion is done using the invariant culture.

  On Windows 98 and Windows Millennium Edition (Windows Me), the registry is not Unicode, and not all Unicode characters are valid for all code pages. A Unicode character that is invalid for the current code page is replaced by the best available match. No exception is thrown.

  Sets the name/value pair on the specified registry key, using the specified registry data type. If the specified key does not exist, it is created.

  The full registry path of the key, beginning with a valid registry root, such as "HKEY_CURRENT_USER". The name of the name/value pair. The value to be stored. The registry data type to use when storing the data.
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.RegistryKey

  This key contains a branch for each user of the computer. The default configuration is supplied for new users on the local computer and for the default current user if the user has not changed preferences. Because Windows 98/ME also supports Registry.Users, applications can access the user-specific information the same way they do under Windows 2000. Each user's information is stored in a separate file, which can be stored locally or on a network server. Windows 98/ME can copy this file to the user's current system so that settings can move from one computer to another with the user.

  Contains information about the default user configuration. This field reads the Windows registry base key HKEY_USERS.