Class

# RegistryItem

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Creates and manages registry items on Windows.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                    | Type                               | Read-Only | Shared |
|-----------------------------------------|------------------------------------|-----------|--------|
| `FolderCount<registryitem.foldercount>` | `Integer</api/data_types/integer>` | ✓         |        |
| `KeyCount<registryitem.keycount>`       | `Integer</api/data_types/integer>` | ✓         |        |
| `Parent<registryitem.parent>`           | RegistryItem                       | ✓         |        |
| `Path<registryitem.path>`               | `String</api/data_types/string>`   | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                      | Parameters                                                                                                          | Returns                            | Shared |
|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `AddFolder<registryitem.addfolder>`       | Name As `String</api/data_types/string>`                                                                            | RegistryItem                       |        |
| `Child<registryitem.child>`               | Name As `String</api/data_types/string>`                                                                            | RegistryItem                       |        |
| `Constructor<registryitem.constructor0>`  | Source As RegistryItem                                                                                              |                                    |        |
| `Constructor<registryitem.constructor1>`  | Path As `String</api/data_types/string>`, Create As `Boolean</api/data_types/boolean>` = `True</api/language/true>` |                                    |        |
| `DefaultValue<registryitem.defaultvalue>` |                                                                                                                     | `Variant</api/data_types/variant>` |        |
| `Delete<registryitem.delete>`             | Name As `String</api/data_types/string>`                                                                            |                                    |        |
| `Item<registryitem.item>`                 | Index As `Integer</api/data_types/integer>`                                                                         | RegistryItem                       |        |
| `KeyType<registryitem.keytype>`           | Index As `Integer</api/data_types/integer>`                                                                         | `Integer</api/data_types/integer>` |        |
| `Name<registryitem.name>`                 | Index As `Integer</api/data_types/integer>`                                                                         | `String</api/data_types/string>`   |        |
| `Value<registryitem.value>`               | name As `String</api/data_types/string>`                                                                            | `Variant</api/data_types/variant>` |        |

## Property descriptions

<div id="registryitem.foldercount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.FolderCount

**FolderCount** As `Integer</api/data_types/integer>`

> The number of child folders contained with the <span class="title-ref">RegistryItem</span>.
>
> This property is read-only.

<div id="registryitem.keycount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.KeyCount

**KeyCount** As `Integer</api/data_types/integer>`

> The number of keys contained within the <span class="title-ref">RegistryItem</span>.
>
> This property is read-only.

<div id="registryitem.parent">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Parent

**Parent** As **RegistryItem**

> The RegistryItem's parent.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> You cannot get the parent of a hive. Each hive is considered a root.
>
> </div>
>
> This property is read-only.

<div id="registryitem.path">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Path

**Path** As `String</api/data_types/string>`

> The full path to the <span class="title-ref">RegistryItem</span>.
>
> This property is read-only.

## Method descriptions

<div id="registryitem.addfolder">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.AddFolder

**AddFolder**(Name As `String</api/data_types/string>`) As RegistryItem

> Adds the passed item as a folder. Returns a <span class="title-ref">RegistryItem</span>.
>
> Similar to `Child<registryitem.child>`. If the folder with the name already exists, it'll be returned, otherwise it'll be created first

<div id="registryitem.child">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Child

**Child**(Name As `String</api/data_types/string>`) As RegistryItem

> Returns the child named as a <span class="title-ref">RegistryItem</span>.
>
> If the child does not exist, an exception (`RegistryAccessErrorException</api/exceptions/registryaccesserrorexception>`) is raised.

<div id="registryitem.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Constructor

**Constructor**(Source As RegistryItem)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Clones the passed <span class="title-ref">RegistryItem</span>.

<div id="registryitem.constructor1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Constructor

**Constructor**(Path As `String</api/data_types/string>`, Create As `Boolean</api/data_types/boolean>` = `True</api/language/true>`)

> Creates or reads the registry item from the Path passed to it.
>
> The optional parameter *Create* defaults to `True</api/language/true>`; if you set it to `False</api/language/false>`, the path will not be created if the path is not found. A `RegistryAccessErrorException</api/exceptions/registryaccesserrorexception>` occurs when the path is not found (when create is False) or if you do not have permission to create the path (when create is True).
>
> In order to create Registry keys, your app needs to be running with Administrator privileges. However, this is only required for certain parts of the Windows Registry. For example, creating keys under `HKEY_CURRENT_USER` (HKCU) does not require elevated privileges, and can be accessed normally using Xojo's RegistryItem class. Accessing or modifying keys in other root levels such as `HKEY_LOCAL_MACHINE` (HKLM) may require Administrator rights.
>
> On 64-bit Windows, registry keys for `HKEY_LOCAL_MACHINE\SOFTWARE` may instead be created in the `HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node` folder. Refer to the Microsoft document "[32-bit and 64-bit Application Data in the Registry](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.85).aspx)" for additional information about this.
>
> Get the Windows product name from the Registry:
>
> ``` xojo
> Var reg As New RegistryItem("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", False)
> MessageBox(reg.Value("ProductName")) ' Shows Windows product name
> ```
>
> Create a new Registry key (Administer privileges required):
>
> ``` xojo
> Var reg As New RegistryItem("HKEY_LOCAL_MACHINE\SOFTWARE\ACME")
> reg = reg.AddFolder("MyApp")
> reg.Value("Version") = 1.0
> ```

<div id="registryitem.defaultvalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.DefaultValue

**DefaultValue** As `Variant</api/data_types/variant>`

> Sets the default value of the <span class="title-ref">RegistryItem</span>.

<div id="registryitem.delete">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Delete

**Delete**(Name As `String</api/data_types/string>`)

> Deletes the passed <span class="title-ref">RegistryItem</span>.

<div id="registryitem.item">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Item

**Item**(Index As `Integer</api/data_types/integer>`) As RegistryItem

> Returns as a <span class="title-ref">RegistryItem</span> the <span class="title-ref">RegistryItem</span> corresponding to *Index*.
>
> If *Index* is greater or equal than FolderCount, then an `OutofBoundsException</api/exceptions/outofboundsexception>` is raised. The index is zero based.

<div id="registryitem.keytype">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.KeyType

**KeyType**(Index As `Integer</api/data_types/integer>`) As `Integer</api/data_types/integer>`

> Returns as an `Integer</api/data_types/integer>` the key type for the key located at the *index*.
>
> The possible values are:
>
> | Key             | Value |
> |-----------------|-------|
> | Unsupported key | -1    |
> | REG_SZ          | 0     |
> | REG_DWORD       | 1     |
> | REG_BINARY      | 2     |
> | REG_MULTI_SZ    | 3     |
> | REG_EXPAND_SZ   | 4     |
> | REG_QWORD       | 5     |

<div id="registryitem.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Name

**Name**(Index As `Integer</api/data_types/integer>`) As `String</api/data_types/string>`

> Returns as a `String</api/data_types/string>` the name of the <span class="title-ref">RegistryItem</span> corresponding to *Index*.
>
> If *Index* is greater or equal than KeyCount, then an `OutofBoundsException</api/exceptions/outofboundsexception>` is raised. Index is zero based.

<div id="registryitem.value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RegistryItem.Value

**Value**(name As `String</api/data_types/string>`) As `Variant</api/data_types/variant>`

> Sets the <span class="title-ref">RegistryItem</span> value by the passed *Index*. If *Index* is greater or equal than KeyCount, then an `OutofBoundsException</api/exceptions/outofboundsexception>` is raised. Index is zero based.
>
> When assigning Integer literal values, keep in mind that the Integer type size varies between 32-bit and 64-bit builds. In 32-bit builds, an Integer literal is 32-bit which results in a DWORD value set. In 64-bit builds an Integer literal is 64-bit which results in a QWORD value set. If your Registry value needs to be a DWORD in a 64-bit app, be sure to specifically set the Integer value type to 32-bit. You can do this using a specifically typed variable or the CType command:
>
> ``` xojo
> ' Use specific type
> Var value As Int32 = 1100
> reg.Value(App.ExecutableFile.Name) = value
>
> ' Set type using CType
> reg.Value(App.ExecutableFile.Name) = CType(11000, Int32)
> ```
>
> To create a binary key, use a MemoryBlock:
>
> ``` xojo
> Var mb As New MemoryBlock(1)
> mb.Byte(0) = 15
> reg.Value("Key") = mb
> ```

## Notes

The Value method returns valid information for expandable strings, binary and multi-strings. In the case of expandable strings, the string is automatically expands for you and returns it as a `string</api/data_types/string>`. It supports getting and setting 64-bit values. The default value may also be 64-bit.

In the case of multi-strings, you are passed back a `string</api/data_types/string>` that is `Chr</api/text/chr>`(0)-delimited. You can use the `String.Split<string.split>` function to get the individual parts, like this:

``` xojo
part = regValue.ToArray(String.Chr(0))
```

where part is a `String</api/data_types/string>` array.

In the case of a binary value, a `MemoryBlock</api/language/memoryblock>` is returned. You cannot currently set an expandable string, or a multistring. To set a binary string, please pass in a `MemoryBlock</api/language/memoryblock>`.

## Sample code

This code displays the registry entries for the current Windows version:

``` xojo
' Get a registry key
Var reg As New RegistryItem("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", False)

Var lines() As String

' now we look on all values on this key
For i As Integer = 0 To reg.KeyCount - 1
  Var name As String = reg.Name(i)
  Var value As Variant = reg.Value(i)
  lines.Add(name + " -> " + value)
Next

' and display them
Var s As String
s = String.FromArray(lines, EndOfLine)
MessageBox(s)
```

## Compatibility

|                       |                       |
|-----------------------|-----------------------|
| **Project Types**     | Console, Desktop, Web |
| **Operating Systems** | Windows               |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `RegistryAccessErrorException</api/exceptions/registryaccesserrorexception>` error.

</div>
