# Poco::Util

# class WinRegistryKey

Library: Util
Package: Windows
Header: Poco/Util/WinRegistryKey.h

## Description

This class implements a convenient interface to the Windows Registry.

This class is only available on Windows platforms.

## Member Summary

Member Functions: close, deleteKey, deleteValue, exists, getInt, getString, getStringExpand, handleFor, handleSetError, isReadOnly, key, open, setInt, setString, setStringExpand, subKeys, type, values

## Types

### Keys

typedef std::vector < std::string > Keys;

### Values

typedef std::vector < std::string > Values;

## Enumerations

### Type

REGT_NONE = 0

REGT_STRING = 1

REGT_STRING_EXPAND = 2

REGT_DWORD = 4

## Constructors

### WinRegistryKey

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

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

## Destructor

### ~WinRegistryKey

~WinRegistryKey();

Destroys the WinRegistryKey.

## Member Functions

### deleteKey

void deleteKey();

Recursively deletes the key and all subkeys.

### deleteValue

void deleteValue(
const std::string & name
);

Deletes the value with the given name.

Throws a NotFoundException if the value does not exist.

### exists

bool exists();

Returns true if and only if the key exists.

### exists

bool exists(
const std::string & name
);

Returns true if and only if the given value exists under that key.

### getInt

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.

### getString

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.

### getStringExpand

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.

### isReadOnly

bool isReadOnly() const;

Returns true if and only if the key has been opened for read-only access only.

### setInt

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.

### setString

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.

### setStringExpand

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.

### subKeys

void subKeys(
Keys & keys
);

Appends all subKey names to keys.

### type

Type type(
const std::string & name
);

Returns the type of the key value.

### values

void values(
Values & vals
);

Appends all value names to vals;

### close

void close();

### handleFor

static HKEY handleFor(
const std::string & rootKey
);

### handleSetError

void handleSetError(
const std::string & name
);

### key

std::string key() const;

### key

std::string key(
const std::string & valueName
) const;

### open

void open();