Export (0) Print
Expand All

RegistryKey Class

Represents a key-level node in the Windows registry. This class is a registry encapsulation.

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

[<Sealed>]
[<ComVisibleAttribute(true)>]
type RegistryKey =  
    class
        inherit MarshalByRefObject
        interface IDisposable
    end

The RegistryKey type exposes the following members.

  NameDescription
Public propertyHandleGets a SafeRegistryHandle object that represents the registry key that the current RegistryKey object encapsulates.
Public propertyNameRetrieves the name of the key.
Public propertySubKeyCountRetrieves the count of subkeys of the current key.
Public propertyValueCountRetrieves the count of values in the key.
Public propertyViewGets the view that was used to create the registry key.
Top

  NameDescription
Public methodCloseCloses the key and flushes it to disk if its contents have been modified.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodCreateSubKey(String)Creates a new subkey or opens an existing subkey for write access.
Public methodCreateSubKey(String, RegistryKeyPermissionCheck)Creates a new subkey or opens an existing subkey for write access, using the specified permission check option.
Public methodCreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)Creates a subkey or opens a subkey for write access, using the specified permission check and registry options.
Public methodCreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)Creates a new subkey or opens an existing subkey for write access, using the specified permission check option and registry security.
Public methodCreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)Creates a subkey or opens a subkey for write access, using the specified permission check option, registry option, and registry security.
Public methodDeleteSubKey(String)Deletes the specified subkey.
Public methodDeleteSubKey(String, Boolean)Deletes the specified subkey, and specifies whether an exception is raised if the subkey is not found.
Public methodDeleteSubKeyTree(String)Deletes a subkey and any child subkeys recursively.
Public methodDeleteSubKeyTree(String, Boolean)Deletes the specified subkey and any child subkeys recursively, and specifies whether an exception is raised if the subkey is not found.
Public methodDeleteValue(String)Deletes the specified value from this key.
Public methodDeleteValue(String, Boolean)Deletes the specified value from this key, and specifies whether an exception is raised if the value is not found.
Public methodDisposeReleases all resources used by the current instance of the RegistryKey class.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushWrites all the attributes of the specified open registry key into the registry.
Public methodStatic memberFromHandle(SafeRegistryHandle)Creates a registry key from a specified handle.
Public methodStatic memberFromHandle(SafeRegistryHandle, RegistryView)Creates a registry key from a specified handle and registry view setting.
Public methodGetAccessControl()Returns the access control security for the current registry key.
Public methodGetAccessControl(AccessControlSections)Returns the specified sections of the access control security for the current registry key.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetSubKeyNamesRetrieves an array of strings that contains all the subkey names.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValue(String)Retrieves the value associated with the specified name. Returns a null reference (Nothing in Visual Basic) if the name/value pair does not exist in the registry.
Public methodGetValue(String, Object)Retrieves the value associated with the specified name. If the name is not found, returns the default value that you provide.
Public methodGetValue(String, Object, RegistryValueOptions)Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.
Public methodGetValueKindRetrieves the registry data type of the value associated with the specified name.
Public methodGetValueNamesRetrieves an array of strings that contains all the value names associated with this key.
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodStatic memberOpenBaseKeyOpens a new RegistryKey that represents the requested key on the local machine with the specified view.
Public methodStatic memberOpenRemoteBaseKey(RegistryHive, String)Opens a new RegistryKey that represents the requested key on a remote machine.
Public methodStatic memberOpenRemoteBaseKey(RegistryHive, String, RegistryView)Opens a new registry key that represents the requested key on a remote machine with the specified view.
Public methodOpenSubKey(String)Retrieves a subkey as read-only.
Public methodOpenSubKey(String, RegistryKeyPermissionCheck)Retrieves the specified subkey for read or read/write access.
Public methodOpenSubKey(String, Boolean)Retrieves a specified subkey, and specifies whether write access is to be applied to the key.
Public methodOpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)Retrieves the specified subkey for read or read/write access, requesting the specified access rights.
Public methodSetAccessControlApplies Windows access control security to an existing registry key.
Public methodSetValue(String, Object)Sets the specified name/value pair.
Public methodSetValue(String, Object, RegistryValueKind)Sets the value of a name/value pair in the registry key, using the specified registry data type.
Public methodToStringRetrieves a string representation of this key. (Overrides Object.ToString().)
Top

To get an instance of RegistryKey, use one of the static members of the Registry class.

The registry acts as a central repository of information for the operating system and the applications on a computer. The registry is organized in a hierarchical format, based on a logical ordering of the elements stored within it (please see Registry for the base-level items in this hierarchy). When storing information in the registry, select the appropriate location based on the type of information being stored. Be sure to avoid destroying information created by other applications, because this can cause those applications to exhibit unexpected behavior, and can also have an adverse effect upon your own application.

Registry keys are the base unit of organization in the registry, and can be compared to folders in Windows Explorer. A particular key can have subkeys, just as a folder can have subfolders. Each key can be deleted, as long as the user has the appropriate permissions to do so, and the key is not a base key or at the level directly under the base keys. Each key can also have multiple values associated with it (a value can be compared to a file), which are used to store the information — for example, information about an application installed on the computer. Each value holds one particular piece of information, which can be retrieved or updated when required. For instance, you can create a RegistryKey for your company, under the key HKEY_LOCAL_MACHINE\Software, and then a subkey for each application that your company creates. Each subkey holds the information specific to that application, such as color settings, screen location and size, or recognized file extensions.

Note that information stored in the registry is available to other applications and users, and therefore should not be used to store security data or critical application information.

Caution noteCaution

Do not expose RegistryKey objects in such a way that a malicious program could create thousands of meaningless subkeys or key/value pairs. For example, do not allow callers to enter arbitrary keys or values.

Starting in the .NET Framework version 4, the length of a registry key is no longer limited to 255 characters.

The following code example shows how to create a subkey under HKEY_CURRENT_USER, manipulate its contents, and then delete the subkey.

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

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

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

Community Additions

ADD
Show:
© 2014 Microsoft