Registry Class

 

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

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

System.Object
  Microsoft.Win32.Registry

[<AbstractClass>]
[<Sealed>]
[<ComVisibleAttribute(true)>]
type Registry = class end

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticGetValue(String, String, Object)

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.

System_CAPS_pubmethodSystem_CAPS_staticSetValue(String, String, Object)

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

System_CAPS_pubmethodSystem_CAPS_staticSetValue(String, String, Object, RegistryValueKind)

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.

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticClassesRoot

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.

System_CAPS_pubfieldSystem_CAPS_staticCurrentConfig

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.

System_CAPS_pubfieldSystem_CAPS_staticCurrentUser

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

System_CAPS_pubfieldSystem_CAPS_staticDynData

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

System_CAPS_pubfieldSystem_CAPS_staticLocalMachine

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

System_CAPS_pubfieldSystem_CAPS_staticPerformanceData

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

System_CAPS_pubfieldSystem_CAPS_staticUsers

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

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 RegistryKey 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:

CurrentUser

Stores information about user preferences.

LocalMachine

Stores configuration information for the local machine.

ClassesRoot

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

Users

Stores information about the default user configuration.

PerformanceData

Stores performance information for software components.

CurrentConfig

Stores non-user-specific hardware information.

DynData

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

In the .NET Framework version 2.0, the Registry class also contains staticGetValue and SetValue 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 RegistryKey class, when you access a large number of values.

The RegistryKey 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.

This section contains two code examples. The first example demonstrates root keys, and the second example demonstrates the staticGetValue and SetValue methods.

Example 1

The following code example demonstrates how to retrieve the subkeys of the HKEY_USERS key, and print 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.

No code example is currently available or this language may not be supported.

Example 2

The following code example stores values of several data types in an example key, creating the key as it does so, and then retrieves and displays the values. The example demonstrates storing and retrieving the default (nameless) name/value pair, and the use of defaultValue when a name/value pair does not exist.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: