Partager via


CRegKey Class

This class provides methods for manipulating entries in the system registry.

Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

class CRegKey

Members

Public Constructors

Name

Description

CRegKey::CRegKey

The constructor.

CRegKey::~CRegKey

The destructor.

Public Methods

Name

Description

CRegKey::Attach

Call this method to attach an HKEY to the CRegKey object by setting the m_hKey member handle to hKey.

CRegKey::Close

Call this method to release the m_hKey member handle and set it to NULL.

CRegKey::Create

Call this method to create the specified key, if it does not exist as a subkey of hKeyParent.

CRegKey::DeleteSubKey

Call this method to remove the specified key from the registry.

CRegKey::DeleteValue

Call this method to remove a value field from m_hKey.

CRegKey::Detach

Call this method to detach the m_hKey member handle from the CRegKey object and set m_hKey to NULL.

CRegKey::EnumKey

Call this method to enumerate the subkeys of the open registry key.

CRegKey::Flush

Call this method to write all of the attributes of the open registry key into the registry.

CRegKey::GetKeySecurity

Call this method to retrieve a copy of the security descriptor protecting the open registry key.

CRegKey::NotifyChangeKeyValue

This method notifies the caller about changes to the attributes or contents of the open registry key.

CRegKey::Open

Call this method to open the specified key and set m_hKey to the handle of this key.

CRegKey::QueryBinaryValue

Call this method to retrieve the binary data for a specified value name.

CRegKey::QueryDWORDValue

Call this method to retrieve the DWORD data for a specified value name.

CRegKey::QueryGUIDValue

Call this method to retrieve the GUID data for a specified value name.

CRegKey::QueryMultiStringValue

Call this method to retrieve the multistring data for a specified value name.

CRegKey::QueryQWORDValue

Call this method to retrieve the QWORD data for a specified value name.

CRegKey::QueryStringValue

Call this method to retrieve the string data for a specified value name.

CRegKey::QueryValue

Call this method to retrieve the data for the specified value field of m_hKey. Earlier versions of this method are no longer supported and are marked as ATL_DEPRECATED.

CRegKey::RecurseDeleteKey

Call this method to remove the specified key from the registry and explicitly remove any subkeys.

CRegKey::SetBinaryValue

Call this method to set the binary value of the registry key.

CRegKey::SetDWORDValue

Call this method to set the DWORD value of the registry key.

CRegKey::SetGUIDValue

Call this method to set the GUID value of the registry key.

CRegKey::SetKeySecurity

Call this method to set the security of the registry key.

CRegKey::SetKeyValue

Call this method to store data in a specified value field of a specified key.

CRegKey::SetMultiStringValue

Call this method to set the multistring value of the registry key.

CRegKey::SetQWORDValue

Call this method to set the QWORD value of the registry key.

CRegKey::SetStringValue

Call this method to set the string value of the registry key.

CRegKey::SetValue

Call this method to store data in the specified value field of m_hKey. Earlier versions of this method are no longer supported and are marked as ATL_DEPRECATED.

Public Operators

Name

Description

CRegKey::operator HKEY

Converts a CRegKey object to an HKEY.

CRegKey::operator =

Assignment operator.

Public Data Members

Name

Description

CRegKey::m_hKey

Contains a handle of the registry key associated with the CRegKey object.

CRegKey::m_pTM

Pointer to CAtlTransactionManager object

Remarks

CRegKey provides methods for creating and deleting keys and values in the system registry. The registry contains an installation-specific set of definitions for system components, such as software version numbers, logical-to-physical mappings of installed hardware, and COM objects.

CRegKey provides a programming interface to the system registry for a given machine. For example, to open a particular registry key, call CRegKey::Open. To retrieve or modify a data value, call CRegKey::QueryValue or CRegKey::SetValue, respectively. To close a key, call CRegKey::Close.

When you close a key, its registry data is written (flushed) to the hard disk. This process may take several seconds. If your application must explicitly write registry data to the hard disk, you can call the RegFlushKey Win32 function. However, RegFlushKey uses many system resources and should be called only when absolutely necessary.

Security noteSecurity Note

Any methods that allow the caller to specify a registry location have the potential to read data that cannot be trusted. Methods that make use of RegQueryValueEx should take into consideration that this function does not explicitly handle strings which are NULL terminated. Both conditions should be checked for by the calling code.

Requirements

Header: atlbase.h

See Also

Reference

Registry Overview

Registry Functions

Registry Value Types

Concepts

DCOM Sample

Other Resources

ATL Class Overview