SECRegistry Class

class SECRegistry: public CObject

SECRegistry encapsulates the APIs used to access and modify the Windows registry in a single class. The bulk of the SECRegistry member functions pertain to the Win32 API; and a smaller number are used in a Win16 environment.

See the REGDEMO sample in the \SAMPLES\TOOLKIT\STANDARD\UTILITY\REGDEMO directory for a demonstration of this class.

Defined in: SECREG.H

Developer Notes

The following static data members were not accessed correctly when compiled as an extension dll and have been removed from this class. Please use the corresponding constants defined in WINREG.H:

static HKEY hKeyLocalMachine;//HKEY_LOCAL_MACHINE
static HKEY hKeyClassesRoot;//HKEY_CLASSES_ROOT
static HKEY hKeyUsers;//HKEY_USERS
static HKEY hKeyCurrentUser;//HKEY_CURRENT_USER

enum  CreationDisposition

Creation dispositions

enum  CreateOptions

Create options

enum  CreatePermissions

Create Permissions

enum  KeyValueTypes

Key value types

enum  NotifyChangeFilter

Notify change filters

Class Members

Creation/Initialization

SECRegistry()

Constructs a SECRegistry object.

virtual void  Initialize( void )

Initializes data members.

virtual BOOL  Create( LPCTSTR lpszSubkeyName, LPCTSTR name_of_class = NULL, CreateOptions options = optionsNonVolatile, CreatePermissions permissions = permissionAllAccess, LPSECURITY_ATTRIBUTES pSecurityAttributes = NULL, CreationDisposition * pDisposition = NULL )

Creates key in registry (32-bit only).

virtual BOOL  Create( LPCTSTR name_of_subkey, LPCTSTR name_of_class = NULL )

Creates key in registry (16-bit only).

Operations

virtual BOOL  Close( void )

Closes the current key (16 and 32-bit).

virtual BOOL  Connect(HKEY hKeyToOpen = HKEY_CURRENT_USER, LPCTSTR lpszComputerName = NULL, BOOL bCloseKeyOnDisconnect = TRUE)

Establishes a connection with the registry (32-bit only).

virtual BOOL  DeleteKey( LPCTSTR lpszKeyToDelete, BOOL bRecursive = FALSE)

Deletes the specified key from the registry (16 and 32-bit).

virtual BOOL  DeleteValue( LPCTSTR lpszValueToDelete)

Deletes the named registry value of the current key (32-bit only).

virtual BOOL  EnumerateKeys( const DWORD dwSubkeyIndex, CString& strSubkeyName)

Enumerates subkeys of the currently open key (32-bit only).

virtual BOOL  EnumerateKeys( const DWORD dwSubkeyIndex, CString& strSubkeyName, CString& strClassName )

Enumerates subkeys of the currently open key (32-bit only).

virtual BOOL  EnumerateKeys(const DWORD dwSubkeyIndex, LPTSTR lpszSubkeyName, LPDWORD lpdwSubkeyNameSize, LPTSTR lpszClassName = NULL, LPDWORD lpdwClassNameSize = NULL)

Enumerates subkeys of the currently open key (32-bit only).

virtual BOOL  EnumerateKeys( const DWORD dwIndex, LPTSTR lpszBuffer, DWORD dwBufferSize)

Enumerates subkeys of the currently open key (16-bit only).

virtual BOOL  EnumerateValues( const DWORD dwValueIndex, CString& strValueName, KeyValueTypes* pTypeCode = NULL, LPBYTE lpbDataBuffer = NULL, LPDWORD lpdwSizeDataBuffer = NULL)

Enumerates values of the currently open key (32-bit only).

virtual BOOL  EnumerateValues( const DWORD dwValueIndex, CString& strValueName, KeyValueTypes& type_code )

Enumerates the values of the currently open key (32-bit only).

virtual BOOL  EnumerateValues( const DWORD dwValueIndex, CString& strValueName, KeyValueTypes& type_code, LPBYTE lpbDataBuffer, DWORD& dwSizeDataBuffer )

Enumerates the values of the currently open key (32-bit only).

virtual BOOL  Flush( void )

Writes the attributes of the currently open key.

virtual BOOL  GetBinaryValue( LPCTSTR lpszValueName, CByteArray& return_array )

Retrieves a REG_BINARY value (32-bit only).

virtual BOOL  GetDoubleWordValue( LPCTSTR lpszValueName, DWORD& dwReturnValue )

Retrieves a REG_DWORD value (32-bit only).

virtual BOOL  GetSecurity( const SECURITY_INFORMATION security_info, PSECURITY_DESCRIPTOR data_buffer, DWORD& dwSizeDataBuffer)

Encapsulates the RegGetSecurity() call (32-bit only).

virtual BOOL  GetStringValue( LPCTSTR lpszValueName, CString& strReturn )

Retrieves a REG_SZ value (32-bit only).

virtual BOOL  GetStringArrayValue( LPCTSTR name_of_value, CStringArray& return_array )

Retrieves a REG_MULTI_SZ value (32-bit only).

virtual BOOL  GetSubkeys(LPCTSTR lpszBuffer, UINT& nKeys)

Determines the number of subkeys in the curently open key.

virtual BOOL  GetValue( LPCTSTR lpszValueName, CByteArray& return_array )

Retrieves a REG_BINARY value (32-bit only).

virtual BOOL  GetValue( LPCTSTR lpszValueName, DWORD& dwReturnValue )

Retrieves a REG_DWORD value (32-bit only).

virtual BOOL  GetValue( LPCTSTR lpszValueName, CStringArray& return_array )

Retrieves a REG_MULTI_SZ value (32-bit only).

virtual BOOL  GetValue( LPCTSTR lpszValueName, CString& strReturn )

Retrieves a REG_SZ value (32-bit only).

virtual BOOL  Load( LPCTSTR lpszSubkeyName, LPCTSTR lpszFileName )

Loads a registry key from a file (32-bit only).

virtual BOOL  NotifyChange( const HANDLE hEvent = NULL, const NotifyChangeFilter changes_to_be_reported = notifyLastSet, const BOOL bAllSubkeys = changeSpecifiedKeyOnly, const BOOL bWaitForChange = WAIT_FOR_CHANGE )

Indicates when a registry key has changed (32-bit only).

virtual BOOL  Open( LPCTSTR lpszSubkey, const CreatePermissions security_access_mask = permissionAllAccess )

Opens a registry key (32-bit only).

virtual BOOL  Open( LPCTSTR lpszSubkey)

Opens the specified key (32-bit only).

virtual BOOL  QueryInfo( void )

Queries for information about the currently opened key (32-bit only).

virtual BOOL  QueryValue( LPCTSTR lpszValueName, KeyValueTypes& value_type, LPBYTE lpbBuffer, DWORD& dwBufferSize)

Retrieves the type and data for a specified value name (32-bit only).

virtual BOOL  QueryValue( LPCTSTR lpSubKey, SECPBYTE lpbBuffer, LONG& lBufferSize)

Retrieves the type and data for a specified value name (16-bit only).

virtual BOOL  Replace( LPCTSTR lpszSubkeyName, LPCTSTR lpszNewFile, LPCTSTR lpszBackupFile)

Encapsulates the RegReplaceKey API (32-bit only).

virtual BOOL  Restore( LPCTSTR lpszSavedTreeFile, const DWORD dwVolatilityFlags = NULL )

Encapsulates the RegRestoreKey API (32-bit only).

virtual BOOL  Save( LPCTSTR lpszDestFile, LPSECURITY_ATTRIBUTES pSecurityAttributes = NULL )

Encapsulates the RegSaveKey API (32-bit only).

virtual BOOL  SetBinaryValue( LPCTSTR lpszValueName, const CByteArray& bytes_to_write )

Sets a value for the key name specified as REG_BINARY (32-bit only).

virtual BOOL  SetDoubleWordValue( LPCTSTR lpszValueName, DWORD dwValue )

Sets a value for the key name specified as REG_DWORD (32-bit only).

virtual BOOL  SetSecurity( const SECURITY_INFORMATION& SecurityInformation, const PSECURITY_DESCRIPTOR pSecurityDescriptor )

Encapsulates the RegSetKeySecurity API (32-bit only).

virtual BOOL  SetStringValue( LPCTSTR lpszValueName, const CString& string_value )

Sets a value for the key name specified as REG_SZ (32-bit only).

virtual BOOL  SetStringArrayValue( LPCTSTR lpszValueName, const CStringArray& string_array )

Sets a value for the key name specified as REG_MULTI_SZ (32-bit only).

virtual BOOL  SetValue( LPCTSTR lpszValueName, const CByteArray& bytes_to_write )

Sets a value for the key name specified as REG_BINARY (32-bit only).

virtual BOOL  SetValue( LPCTSTR lpszValueName, DWORD dwValue )

Sets a value for the key name specified as REG_DWORD (32-bit only).

virtual BOOL  SetValue( LPCTSTR lpszValueName, const CStringArray& strings_to_write )

Sets a value for the key name specified as REG_MULTI_SZ (32-bit only).

virtual BOOL  SetValue( LPCTSTR lpszValueName, const CString& strWrite )

Sets a value for the key name specified as REG_SZ (32-bit only).

virtual BOOL  SetValue( LPCTSTR lpszValueName, const KeyValueTypes type_of_value_to_set, LPBYTE lpbValueData, const DWORD dwSize )

Sets a value for the key name specified (32-bit only).

virtual BOOL  SetValue( LPCTSTR lpSubKey, const CString& strWrite )

Sets a value for the key name specified (16-bit only).

virtual BOOL  UnLoad( LPCTSTR lpszSubkey )

Encapsulates the RegUnLoadKey API.

static BOOL  KeyToStr(HKEY hKey,CString& strKey)

Converts an HKEY constant to its string equivalent.

static HKEY  StrToKey(const CString& strKey)

Converts a string equivalent to an HKEY value.

LONG  m_lErrorCode

The error code for the last operation.

HKEY  m_hKey

The handle to the currently open registry key.

HKEY  m_hRegistry

The handle to the current registry.

DWORD  m_dwLongestSubkeyNameLength

The longest subkey name length of last queried key.

DWORD  m_dwLongestClassNameLength

The longest class name length of last queried key.

DWORD  m_dwLongestValueNameLength

The longest value name length of last queried key.

DWORD  m_dwLongestValueDataLength

The longest value data length of last queried key.

DWORD  m_dwSecurityDescriptorLength

The longest security descriptor length of last queried key.

FILETIME  m_fileTimeLastWrite

The time the last queried key was written to.

CString  m_strClassName

The class name of the currently open key.

CString  m_strComputerName

The computer name for the currently connected registry.

CString  m_strKeyName

The name of the currently open key.

CString  m_strRegistryName

The name of the currently connected registry.

DWORD  m_dwNumberOfSubkeys

The number of subkeys of the last queried key.

DWORD  m_dwNumberOfValues

The number of values in the last queried key.

CTime  m_timeLastWrite

The time the last queried key was written to.

BOOL  m_bRemote

Indicates whether the registry is local or on a remote system.

BOOL  m_bCloseKeyOnDisconnect

Incidates whether the registry key should be closed when done.