# 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, getBinary, getInt, getInt64, getString, getStringExpand, handle, handleFor, handleSetError, isReadOnly, key, open, setBinary, setInt, setInt64, 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_BINARY = 3

REGT_DWORD = 4

REGT_DWORD_BIG_ENDIAN = 5

REGT_LINK = 6

REGT_MULTI_STRING = 7

REGT_RESOURCE_LIST = 8

REGT_FULL_RESOURCE_DESCRIPTOR = 9

REGT_RESOURCE_REQUIREMENTS_LIST = 10

REGT_QWORD = 11

## 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.

### getBinary

std::vector < char > getBinary(
const std::string & name
);

Returns the string value (REG_BINARY) with the given name. An empty name denotes the default value.

Throws a NotFoundException if the value does not exist.

### 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.

### getInt64

Poco::Int64 getInt64(
const std::string & name
);

Returns the numeric value (REG_QWORD) 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.

### setBinary

void setBinary(
const std::string & name,
const std::vector < char > & value
);

Sets the string value (REG_BINARY) with the given name. An empty name denotes the default value.

### 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.

### setInt64

void setInt64(
const std::string & name,
Poco::Int64 value
);

Sets the numeric (REG_QWORD) 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();

### handle

HKEY handle();

### 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();