Library: Util
Package: Windows
Header: Poco/Util/WinRegistryKey.h
This class implements a convenient interface to the Windows Registry.
This class is only available on Windows platforms.
Member Functions: close, deleteKey, deleteValue, exists, getInt, getString, getStringExpand, handleFor, handleSetError, isReadOnly, key, open, setInt, setString, setStringExpand, subKeys, type, values
typedef std::vector < std::string > Keys;
typedef std::vector < std::string > Values;
REGT_NONE = 0
REGT_STRING = 1
REGT_DWORD = 4
WinRegistryKey(
const std::string & key,
bool readOnly = false,
REGSAM extraSam = 0
);
Creates the WinRegistryKey.
The key must start with one of the root key names like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
If readOnly is true, then only read access to the registry is available and any attempt to write to the registry will result in an exception.
extraSam is used to pass extra flags (in addition to KEY_READ and KEY_WRITE) to the samDesired argument of RegOpenKeyEx() or RegCreateKeyEx().
WinRegistryKey(
HKEY hRootKey,
const std::string & subKey,
bool readOnly = false,
REGSAM extraSam = 0
);
Creates the WinRegistryKey.
If readOnly is true, then only read access to the registry is available and any attempt to write to the registry will result in an exception.
extraSam is used to pass extra flags (in addition to KEY_READ and KEY_WRITE) to the samDesired argument of RegOpenKeyEx() or RegCreateKeyEx().
~WinRegistryKey();
Destroys the WinRegistryKey.
void deleteKey();
Recursively deletes the key and all subkeys.
void deleteValue(
const std::string & name
);
Deletes the value with the given name.
Throws a NotFoundException if the value does not exist.
bool exists();
Returns true if and only if the key exists.
bool exists(
const std::string & name
);
Returns true if and only if the given value exists under that key.
int getInt(
const std::string & name
);
Returns the numeric value (REG_DWORD) with the given name. An empty name denotes the default value.
Throws a NotFoundException if the value does not exist.
std::string getString(
const std::string & name
);
Returns the string value (REG_SZ) with the given name. An empty name denotes the default value.
Throws a NotFoundException if the value does not exist.
std::string getStringExpand(
const std::string & name
);
Returns the string value (REG_EXPAND_SZ) with the given name. An empty name denotes the default value. All references to environment variables (%VAR%) in the string are expanded.
Throws a NotFoundException if the value does not exist.
bool isReadOnly() const;
Returns true if and only if the key has been opened for read-only access only.
void setInt(
const std::string & name,
int value
);
Sets the numeric (REG_DWORD) value with the given name. An empty name denotes the default value.
void setString(
const std::string & name,
const std::string & value
);
Sets the string value (REG_SZ) with the given name. An empty name denotes the default value.
void setStringExpand(
const std::string & name,
const std::string & value
);
Sets the expandable string value (REG_EXPAND_SZ) with the given name. An empty name denotes the default value.
void subKeys(
Keys & keys
);
Appends all subKey names to keys.
Type type(
const std::string & name
);
Returns the type of the key value.
void values(
Values & vals
);
Appends all value names to vals;
void close();
static HKEY handleFor(
const std::string & rootKey
);
void handleSetError(
const std::string & name
);
std::string key() const;
std::string key(
const std::string & valueName
) const;
void open();