OWLNext 7.0
Borland's Object Windows Library for the modern age
|
Encapsulates a registration key in the Windows Registry. More...
#include <owl/registry.h>
Classes | |
struct | TInfo |
Data structure returned by QueryInfo. More... | |
class | TSecurityDescriptor |
Encapsulates a SECURITY_DESCRIPTOR. More... | |
Public Types | |
enum | TCreateOK { CreateOK , NoCreate } |
Enumeration used to specify whether a key should be created (or simply opened). More... | |
typedef HKEY | THandle |
Public Member Functions | |
TRegKey (THandle baseKey, tstring keyName, REGSAM samDesired=KEY_ALL_ACCESS, TCreateOK createOK=CreateOK) | |
Creates or opens a key given a base key and a subkey name. | |
TRegKey (THandle baseKey, LPCTSTR keyName, REGSAM samDesired=KEY_ALL_ACCESS, TCreateOK createOK=CreateOK) | |
LPCTSTR overload. | |
TRegKey (const TRegKeyIterator &iter, REGSAM samDesired=KEY_ALL_ACCESS) | |
Constructs a key given the current position of a TRegKeyIterator. | |
TRegKey (THandle aliasKey, bool shouldClose, tstring keyName) | |
Constructs a TRegKey object around an existing key. | |
TRegKey (THandle aliasKey, bool shouldClose=false, LPCTSTR keyName=nullptr) | |
LPCTSTR overload. | |
TRegKey (TRegKey &&) noexcept | |
Move constructor; steals the innards of the given object. | |
TRegKey (const TRegKey &)=delete | |
TRegKey & | operator= (const TRegKey &)=delete |
~TRegKey () | |
Closes the underlying key handle, if owned. | |
operator THandle () const | |
Returns the HANDLE identifying this registry key. | |
auto | GetHandle () const -> THandle |
long | DeleteKey (LPCTSTR subKeyName) |
Deletes the specified subkey of this registry key. | |
long | DeleteKey (const tstring &subKeyName) |
long | NukeKey (LPCTSTR subKeyName) |
Completely eliminates a child key, including any of its subkeys. | |
long | NukeKey (const tstring &subKeyName) |
long | Flush () const |
Writes the attribute of this key in the registry. | |
long | Save (LPCTSTR fileName) |
Saves this key and all of its subkeys and values to the specified file. | |
long | Save (const tstring &fileName) |
long | LoadKey (LPCTSTR subKeyName, LPCTSTR fileName) |
Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores registration information from a specified file into that subkey. | |
long | LoadKey (const tstring &subKeyName, const tstring &fileName) |
long | ReplaceKey (LPCTSTR subKeyName, LPCTSTR newFileName, LPCTSTR oldFileName) |
Replaces the file backing this key and all of its subkeys with another file, so that when the system is next started, the key and subkeys will have the values stored in the new file. | |
long | ReplaceKey (const tstring &subKeyName, const tstring &newFileName, const tstring &oldFileName) |
long | Restore (LPCTSTR fileName, uint32 options=0) |
Reads the registry information in a specified file and copies it over this key. | |
long | Restore (const tstring &fileName, uint32 options=0) |
long | UnLoadKey (LPCTSTR subKeyName) |
Unloads this key and its subkeys from the registry. | |
long | UnLoadKey (const tstring &subKeyName) |
long | QueryInfo (TCHAR *class_, DWORD *classSize, DWORD *subkeyCount, DWORD *maxSubkeyNameSize, DWORD *maxSubkeyClassSize, DWORD *valueCount, DWORD *maxValueNameSize, DWORD *maxValueDataSize, DWORD *securityDescriptorSize, PFILETIME lastWriteTime) const |
Retrieves information about this registry key. | |
auto | QueryInfo () const -> TInfo |
Functional-style overload. | |
LPCTSTR | GetName () const |
Returns a string identifying this key. | |
auto | HasSubkey (const tstring &keyName) const -> bool |
Returns true if this key has a subkey with the given name. | |
auto | GetSubkey (const tstring &keyName, REGSAM samDesired=KEY_READ) const -> std::optional< TRegKey > |
Returns the subkey with the given name, if it exists. | |
uint32 | GetSubkeyCount () const |
Returns the number of subkeys attached to this key. | |
auto | HasValue (const tstring &valueName) const -> bool |
Return true if this key has a value with the given name. | |
auto | GetValue (const tstring &valueName) const -> std::optional< TRegValue > |
Returns the value with the given name, if it exists within this key. | |
uint32 | GetValueCount () const |
Returns the number of values attached to this key. | |
template<typename T > | |
auto | GetValueOrDefault (const tstring &valueName, T defaultValue) const |
Returns the value of the given name, if it exists, or the given default value, otherwise. | |
long | EnumKey (int index, TCHAR *subKeyName, int subKeyNameSize) const |
Enumerates the subkeys of this registry key. | |
long | SetValue (LPCTSTR valName, uint32 type, const uint8 *data, uint32 dataSize) const |
Associates a value with this key. | |
long | SetValue (const tstring &valName, uint32 type, const uint8 *data, uint32 dataSize) const |
long | SetValue (LPCTSTR valName, uint32 data) const |
Associates a 4-byte value with this key. | |
long | SetValue (const tstring &valName, uint32 data) const |
long | SetValue (LPCTSTR valName, const tstring &value) const |
Associates a string value with this key. | |
long | SetValue (const tstring &valName, const tstring &value) const |
long | QueryValue (LPCTSTR valName, uint32 *type, uint8 *data, uint32 *dataSize) const |
Retrieves the value associated with the unnamed value for this key in the registry. | |
long | QueryValue (const tstring &valName, uint32 *type, uint8 *data, uint32 *dataSize) const |
long | DeleteValue (LPCTSTR valName) const |
Removes a named value from this registry key. | |
long | DeleteValue (const tstring &valName) const |
long | EnumValue (int index, TCHAR *valueName, uint32 &valueNameSize, uint32 *type=nullptr, uint8 *data=nullptr, uint32 *dataSize=nullptr) const |
Enumerates the values associated with this key. | |
Security attributes | |
auto | GetSecurity (SECURITY_INFORMATION infoRequested, PSECURITY_DESCRIPTOR secDesc, DWORD *secDescSize) const -> long |
Retrieves a copy of the security descriptor protecting this registry key. | |
auto | GetSecurity (SECURITY_INFORMATION infoRequested) const -> TSecurityDescriptor |
Retrieves a copy of the security descriptor protecting this registry key. | |
auto | SetSecurity (SECURITY_INFORMATION infoToSet, PSECURITY_DESCRIPTOR secDesc) const -> long |
Sets the security descriptor of this key. | |
void | SetSecurity (SECURITY_INFORMATION infoToSet, const TSecurityDescriptor &s) const |
Sets the security descriptor of this key. | |
Static Public Member Functions | |
Accessors to system predefined registry keys | |
static auto | GetClassesRoot () -> TRegKey & |
Special predefined root key used by shell and OLE applications (HKEY_CLASSES_ROOT ). | |
static auto | GetClassesRootClsid () -> TRegKey & |
Commonly used subkey by shell and OLE applications (HKEY_CLASSES_ROOT\CLSID ). | |
static auto | GetCurrentConfig () -> TRegKey & |
Special predefined root key containing information about the current hardware profile of the local computer system (HKEY_CURRENT_CONFIG ). | |
static auto | GetCurrentUser () -> TRegKey & |
Special predefined root key defining the preferences of the current user (HKEY_CURRENT_USER ). | |
static auto | GetLocalMachine () -> TRegKey & |
Special predefined root key defining the physical state of the computer (HKEY_LOCAL_MACHINE ). | |
static auto | GetPerformanceData () -> TRegKey & |
Special predefined root key used to obtain performance data (HKEY_PERFORMANCE_DATA ). | |
static auto | GetUsers () -> TRegKey & |
Special predefined root key defining the default user configuration (HKEY_USERS ). | |
Protected Attributes | |
THandle | Key |
This Key's Handle. | |
tstring | Name |
This Key's Name. | |
DWORD | SubkeyCount |
Number of subkeys. | |
DWORD | ValueCount |
Number of value entries. | |
bool | ShouldClose |
Should this key be closed on destruction. | |
Encapsulates a registration key in the Windows Registry.
Definition at line 114 of file registry.h.
Definition at line 117 of file registry.h.
Enumeration used to specify whether a key should be created (or simply opened).
Enumerator | |
---|---|
CreateOK | Create key if it does not exist. |
NoCreate | Don't create, simply open. |
Definition at line 122 of file registry.h.
owl::TRegKey::TRegKey | ( | THandle | baseKey, |
tstring | keyName, | ||
REGSAM | samDesired = KEY_ALL_ACCESS, | ||
TCreateOK | createOK = CreateOK ) |
Creates or opens a key given a base key and a subkey name.
The user can specify the desired access rights to the key and provide an ok-to-create or open-only indicator. To check whether a subkey exists before creating a TRegKey, you can call TRegKey::HasSubkey on the base key.
Definition at line 128 of file registry.cpp.
References __except, __try, _T, CHECK, CreateOK, GetExceptionCode, Key, Name, QueryInfo(), SubkeyCount, and ValueCount.
owl::TRegKey::TRegKey | ( | THandle | baseKey, |
LPCTSTR | keyName, | ||
REGSAM | samDesired = KEY_ALL_ACCESS, | ||
TCreateOK | createOK = CreateOK ) |
LPCTSTR overload.
Forwards to TRegKey::TRegKey(THandle baseKey, tstring keyName, REGSAM, TCreateOK).
nullptr
for the key name, it will be translated to an empty string. Definition at line 173 of file registry.cpp.
|
explicit |
Constructs a key given the current position of a TRegKeyIterator.
Definition at line 183 of file registry.cpp.
References __except, __try, _MAX_PATH, _T, CHECK, COUNTOF, GetExceptionCode, Key, Name, QueryInfo(), SubkeyCount, and ValueCount.
Constructs a TRegKey object around an existing key.
Commonly used for wrapping the preexisting pseudo-keys, such as HKEY_CURRENT_USER. If true
is passed for parameter shouldClose
, then the object takes ownership of the handle, and the handle will be closed when the object is destructed.
Definition at line 231 of file registry.cpp.
References __except, __try, _T, CHECK, GetExceptionCode, Key, Name, QueryInfo(), SubkeyCount, and ValueCount.
|
explicit |
LPCTSTR overload.
Forwards to TRegKey::TRegKey(THandle, bool shouldClose, tstring keyName).
nullptr
for the key name, it will be translated to an empty string. Definition at line 264 of file registry.cpp.
|
noexcept |
Move constructor; steals the innards of the given object.
Definition at line 273 of file registry.cpp.
|
delete |
owl::TRegKey::~TRegKey | ( | ) |
Closes the underlying key handle, if owned.
Definition at line 288 of file registry.cpp.
References _T, Key, ShouldClose, and WARN.
Definition at line 183 of file registry.h.
Deletes the specified subkey of this registry key.
Definition at line 878 of file registry.h.
References Key.
Definition at line 383 of file registry.h.
Removes a named value from this registry key.
Definition at line 1054 of file registry.h.
References Key.
Enumerates the subkeys of this registry key.
Definition at line 869 of file registry.h.
References Key.
|
inline |
Enumerates the values associated with this key.
Copy the value name and data block associated with the passed index.
Definition at line 1087 of file registry.h.
References Key.
|
inline |
Writes the attribute of this key in the registry.
Definition at line 886 of file registry.h.
References Key.
Special predefined root key used by shell and OLE applications (HKEY_CLASSES_ROOT
).
Registry entries subordinate to this key define types (or classes) of documents and the properties associated with those types. Shell and COM applications use the information stored under this key.
Definition at line 32 of file registry.cpp.
References _T.
Commonly used subkey by shell and OLE applications (HKEY_CLASSES_ROOT\CLSID
).
Definition at line 41 of file registry.cpp.
References _T.
Special predefined root key containing information about the current hardware profile of the local computer system (HKEY_CURRENT_CONFIG
).
The information under this key describes only the differences between the current hardware configuration and the standard configuration. Information about the standard hardware configuration is stored under the Software and System keys of HKEY_LOCAL_MACHINE
.
Definition at line 55 of file registry.cpp.
References _T.
Special predefined root key defining the preferences of the current user (HKEY_CURRENT_USER
).
These preferences include the settings of environment variables, data about program groups, colors, printers, network connections, and application preferences. This key makes it easier to establish the current user's settings; the key maps to the current user's branch in HKEY_USERS. Under 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.
Definition at line 72 of file registry.cpp.
References _T.
Definition at line 180 of file registry.h.
Special predefined root key defining the physical state of the computer (HKEY_LOCAL_MACHINE
).
Includes data about the bus type, system memory, and installed hardware and software. It contains subkeys that hold current configuration data, including Plug and Play information (the Enum branch, which includes a complete list of all hardware that has ever been on the system), network logon preferences, network security information, software-related information (such as server names and the location of the server), and other system information.
Definition at line 87 of file registry.cpp.
References _T.
|
inline |
Special predefined root key used to obtain performance data (HKEY_PERFORMANCE_DATA
).
The data is not actually stored in the registry; the registry functions cause the system to collect the data from its source.
Definition at line 98 of file registry.cpp.
References _T.
|
inline |
Retrieves a copy of the security descriptor protecting this registry key.
infoRequested | indicates the requested security information. |
TXRegistry | is thrown on failure. |
Definition at line 911 of file registry.h.
|
inline |
Retrieves a copy of the security descriptor protecting this registry key.
Definition at line 897 of file registry.h.
auto owl::TRegKey::GetSubkey | ( | const tstring & | keyName, |
REGSAM | samDesired = KEY_READ ) const -> std::optional<TRegKey> |
Returns the subkey with the given name, if it exists.
If the key does not exist, std::nullopt is returned. If access is denied, or any other error occurs, a TXRegistry exception is thrown. The key name may include a path with subkey names separated by backslash, e.g. "Software\\Program".
samDesired | A mask that specifies the desired access rights to the key to be opened. For possible values of this parameter, see the Windows API documentation. |
Definition at line 376 of file registry.cpp.
References _T, and PRECONDITION.
|
inline |
Returns the number of subkeys attached to this key.
Definition at line 992 of file registry.h.
References SubkeyCount.
Special predefined root key defining the default user configuration (HKEY_USERS
).
Registry entries subordinate to this key define the default user configuration for new users on the local computer and the user configuration for the current user.
Definition at line 110 of file registry.cpp.
References _T.
Returns the value with the given name, if it exists within this key.
If the value does not exist, std::nullopt is returned. If the given name is empty, the default value is assumed, which always exists. If access is denied, or any other error occurs, a TXRegistry exception is thrown.
Definition at line 402 of file registry.cpp.
References PRECONDITION.
|
inline |
Returns the number of values attached to this key.
Definition at line 1000 of file registry.h.
References ValueCount.
|
inline |
Returns the value of the given name, if it exists, or the given default value, otherwise.
A conversion of the TRegValue to type T is attempted. The provided default value must be convertible to T. The types supported for T are owl::uint32, owl::uint64 and owl::tstring.
Definition at line 336 of file registry.h.
Returns true if this key has a subkey with the given name.
If an error occurs, e.g. access is denied, it is assumed the subkey exists. The key name may include a path with subkey names separated by backslash, e.g. "Software\\Program".
Definition at line 354 of file registry.cpp.
References PRECONDITION.
Return true if this key has a value with the given name.
If the given name is empty, the default value is assumed, which always exists. If an error occurs, e.g. access is denied, it is assumed the value exists.
Definition at line 390 of file registry.cpp.
References PRECONDITION.
Definition at line 281 of file registry.h.
Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores registration information from a specified file into that subkey.
This registration information is in the form of a hive. A hive is a discrete body of keys, subkeys, and values that is rooted at the top of the registry hierarchy. A hive is backed by a single file and a .LOG file.
Definition at line 956 of file registry.h.
References Key.
Definition at line 187 of file registry.h.
Completely eliminates a child key, including any of its subkeys.
Definition at line 411 of file registry.cpp.
References DeleteKey(), GetName(), and GetSubkey().
|
inline |
Returns the HANDLE identifying this registry key.
Definition at line 861 of file registry.h.
Functional-style overload.
Definition at line 326 of file registry.cpp.
References _T, MAX_PATH, and QueryInfo().
long owl::TRegKey::QueryInfo | ( | TCHAR * | class_, |
DWORD * | classSize, | ||
DWORD * | subkeyCount, | ||
DWORD * | maxSubkeyNameSize, | ||
DWORD * | maxSubkeyClassSize, | ||
DWORD * | valueCount, | ||
DWORD * | maxValueNameSize, | ||
DWORD * | maxValueDataSize, | ||
DWORD * | securityDescriptorSize, | ||
PFILETIME | lastWriteTime ) const |
Retrieves information about this registry key.
Wrapper for RegQueryInfoKey in the Windows API.
Definition at line 302 of file registry.cpp.
References Key.
|
inline |
Definition at line 379 of file registry.h.
|
inline |
Retrieves the value associated with the unnamed value for this key in the registry.
Definition at line 1042 of file registry.h.
References Key.
|
inline |
Definition at line 285 of file registry.h.
|
inline |
Replaces the file backing this key and all of its subkeys with another file, so that when the system is next started, the key and subkeys will have the values stored in the new file.
Definition at line 966 of file registry.h.
References Key.
Definition at line 289 of file registry.h.
Reads the registry information in a specified file and copies it over this key.
This registry information may be in the form of a key and multiple levels of subkeys.
Definition at line 976 of file registry.h.
References Key.
Definition at line 277 of file registry.h.
Saves this key and all of its subkeys and values to the specified file.
Definition at line 944 of file registry.h.
References Key.
|
inline |
Sets the security descriptor of this key.
infoToSet | indicates the security information to set. |
TXRegistry | is thrown on failure. |
Definition at line 935 of file registry.h.
References _T, owl::TRegKey::TSecurityDescriptor::GetData(), and SetSecurity().
|
inline |
Sets the security descriptor of this key.
Definition at line 922 of file registry.h.
Definition at line 375 of file registry.h.
Definition at line 371 of file registry.h.
|
inline |
Definition at line 367 of file registry.h.
Associates a string value with this key.
Definition at line 1032 of file registry.h.
References SetValue().
Associates a 4-byte value with this key.
Definition at line 1024 of file registry.h.
References SetValue().
Definition at line 293 of file registry.h.
Unloads this key and its subkeys from the registry.
Definition at line 984 of file registry.h.
References Key.
|
protected |
This Key's Handle.
Definition at line 392 of file registry.h.
|
protected |
This Key's Name.
Definition at line 393 of file registry.h.
|
protected |
Should this key be closed on destruction.
Definition at line 396 of file registry.h.
|
protected |
Number of subkeys.
Definition at line 394 of file registry.h.
|
protected |
Number of value entries.
Definition at line 395 of file registry.h.