wxRuby Documentation Home

# Wx::RegKey

RegKey is a class representing the Windows registry (it is only available
under Windows). One can create, query and delete registry keys using this
class.

The Windows registry is easy to understand. There are five registry keys,
namely:

1. HKEY_CLASSES_ROOT (HKCR)
2. HKEY_CURRENT_USER (HKCU)
3. HKEY_LOCAL_MACHINE (HKLM)
4. HKEY_CURRENT_CONFIG (HKCC)
5. HKEY_USERS (HKU)

After creating a key, it can hold a value. The values can be:

1. String Value
2. Binary Value
3. DWORD Value
4. Multi String Value
5. Expandable String Value

## Derived from

None

## Example

RegKey *pRegKey = new RegKey("HKEY_LOCAL_MACHINE

Software\\MyKey");

//will create the Key if it does not exist if( !pRegKey→Exists() ) pRegKey→Create(); //will create a new value MYVALUE and set it to 12 pRegKey→SetValue(“MYVALUE”,12); //Query for the Value and Retrieve it long lMyVal; String strTemp; pRegKey→QueryValue(“MYVALUE”,&lMyVal); strTemp.Printf(“MessageBox(strTemp,”Registry Value",0,this); //Retrive the number of SubKeys and enumerate them Integer nSubKeys; pRegKey→GetKeyInfo(&nSubKeys,NULL,NULL,NULL); pRegKey→GetFirstKey(strTemp,1); for(int i=0;i<nSubKeys;i++) { MessageBox(strTemp,“SubKey Name”,0,this); pRegKey→GetNextKey(strTemp,1); }

## Methods

- RegKey.new
- RegKey#close
- RegKey#create
- RegKey#delete_self
- RegKey#delete_key
- RegKey#delete_value
- RegKey#exists
- RegKey#get_name
- RegKey#get_first_key
- RegKey#get_first_value
- RegKey#get_key_info
- RegKey#get_next_key
- RegKey#get_next_value
- RegKey#has_value
- RegKey#has_values
- RegKey#has_sub_key
- RegKey#has_sub_keys
- RegKey#is_empty
- RegKey#is_opened
- RegKey#open
- RegKey#query_value
- RegKey#rename
- RegKey#rename_value
- RegKey#set_value

### RegKey.new

RegKey.new(%(arg-type)String% strKey)

The constructor to set the full name of the key.

RegKey.new(%(arg-type)RegKey% keyParent, String strKey)

The constructor to set the full name of the key under a previously created parent.

### RegKey#close

close()

Closes the key.

### RegKey#create

Boolean create(%(arg-type)Boolean% bOkIfExists = true)

Creates the key. Will fail if the key already exists and bOkIfExists is false.

### RegKey#delete_self

delete_self()

Deletes this key and all of its subkeys and values recursively.

### RegKey#delete_key

delete_key(%(arg-type)Char% szKey)

Deletes the subkey with all of its subkeys/values recursively.

### RegKey#delete_value

delete_value(%(arg-type)Char% szKey)

Deletes the named value.

### RegKey#exists

Boolean exists()

Returns true if the key exists.

### RegKey#get_name

String get_name(%(arg-type)Boolean% bShortPrefix = true)

Gets the name of the registry key.

### RegKey#get_first_key

Boolean get_key_value(%(arg-type)String% strKeyName, Integer lIndex)

Gets the first key.

### RegKey#get_first_value

Boolean get_first_value(%(arg-type)String% strValueName, Integer lIndex)

Gets the first value of this key.

### RegKey#get_key_info

Boolean exists(%(arg-type)Integer% pnSubKeys, Integer pnValues, Integer pnMaxValueLen)

Gets information about the key.

#### Parameters

- pnSubKeys The number of subkeys.
- pnMaxKeyLen The maximum length of the subkey name.
- pnValues The number of values.

### RegKey#get_next_key

Boolean get_next_key(%(arg-type)String% strKeyName, Integer lIndex)

Gets the next key.

### RegKey#get_next_value

Boolean get_next_value(%(arg-type)String% strValueName, Integer lIndex)

Gets the next key value for this key.

### RegKey#has_value

Boolean has_value(%(arg-type)Char% szValue)

Returns true if the value exists.

### RegKey#has_values

Boolean has_values()

Returns true if any values exist.

### RegKey#has_sub_key

Boolean has_sub_key(%(arg-type)Char% szKey)

Returns true if given subkey exists.

### RegKey#has_sub_keys

Boolean has_sub_keys()

Returns true if any subkeys exist.

### RegKey#is_empty

Boolean is_empty()

Returns true if this key is empty, nothing under this key.

### RegKey#is_opened

Boolean is_opened()

Returns true if the key is opened.

### RegKey#open

Boolean open(%(arg-type)AccessMode% mode = Write)

Explicitly opens the key. This method also allows the key to be opened in
read-only mode by passing `RegKey::Read` instead of default
`RegKey::Write` parameter.

### RegKey#query_value

Boolean query_value(%(arg-type)Char% szValue, String strValue)

Retrieves the string value.

Boolean query_value(%(arg-type)Char% szValue, Integer plValue)

Retrieves the numeric value.

### RegKey#rename

Boolean rename(%(arg-type)Char% szNewName)

Renames the key.

### RegKey#rename_value

Boolean rename_value(%(arg-type)Char% szValueOld, Char szValueNew)

Renames a value.

### RegKey#set_value

Boolean set_value(%(arg-type)Char% szValue, Integer lValue)

Sets the numeric value.

[This page automatically generated from the Textile source at 2023-06-09 00:45:31 +0000]