# WinRegistry

Import: `import com.install4j.api.windows.WinRegistry;`

```java
public class WinRegistry
```

Collection of static methods to access the Microsoft Windows registry.

If `RegistryRoot.HKEY_CURRENT_USER` is specified, the correct
result for the original user is returned even if executed in the elevated helper.

| Type | Kind | Description |
|---|---|---|
## Nested types

| [WinRegistry.ExpandString](WinRegistry.ExpandString.md) | class | Class to represent Strings with type REG_EXPAND_SZ. |

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`keyExists(RegistryRoot, String)`](#keyexists-registryroot-string) | `boolean` | Checks if a registry key exists. |
| [`createKey(RegistryRoot, String)`](#createkey-registryroot-string) | `boolean` | Creates a registry key. |
| [`getValue(RegistryRoot, String, String)`](#getvalue-registryroot-string-string) | `Object` | Retrieves a registry value. |
| [`setValue(RegistryRoot, String, String, Object)`](#setvalue-registryroot-string-string-object) | `boolean` | Sets a registry value. |
| [`deleteValue(RegistryRoot, String, String)`](#deletevalue-registryroot-string-string) | `void` | Deletes a registry value. |
| [`deleteKey(RegistryRoot, String, boolean)`](#deletekey-registryroot-string-boolean) | `void` | Deletes a registry key. |
| [`getSubKeyNames(RegistryRoot, String)`](#getsubkeynames-registryroot-string) | `String[]` | Retrieves the subkeys of a registry key. |
| [`getValueNames(RegistryRoot, String)`](#getvaluenames-registryroot-string) | `String[]` | Retrieves the exiting value names of a registry key. |
| [`saveKey(RegistryRoot, String, String)`](#savekey-registryroot-string-string) | `boolean` | Save a subtree of the registry to a file. |
| [`restoreKey(RegistryRoot, String, String)`](#restorekey-registryroot-string-string) | `boolean` | Restore a subtree of the registry from a file. |
| [`keyExists(RegistryRoot, String, RegistryView)`](#keyexists-registryroot-string-registryview) | `boolean` | Checks if a registry key exists. |
| [`createKey(RegistryRoot, String, RegistryView)`](#createkey-registryroot-string-registryview) | `boolean` | Creates a registry key. |
| [`getValue(RegistryRoot, String, String, RegistryView)`](#getvalue-registryroot-string-string-registryview) | `Object` | Retrieves a registry value. |
| [`setValue(RegistryRoot, String, String, Object, RegistryView)`](#setvalue-registryroot-string-string-object-registryview) | `boolean` | Sets a registry value. |
| [`deleteValue(RegistryRoot, String, String, RegistryView)`](#deletevalue-registryroot-string-string-registryview) | `void` | Deletes a registry value. |
| [`deleteKey(RegistryRoot, String, boolean, RegistryView)`](#deletekey-registryroot-string-boolean-registryview) | `void` | Deletes a registry key. |
| [`getSubKeyNames(RegistryRoot, String, RegistryView)`](#getsubkeynames-registryroot-string-registryview) | `String[]` | Retrieves the subkeys of a registry key. |
| [`getValueNames(RegistryRoot, String, RegistryView)`](#getvaluenames-registryroot-string-registryview) | `String[]` | Retrieves the exiting value names of a registry key. |
| [`saveKey(RegistryRoot, String, String, RegistryView)`](#savekey-registryroot-string-string-registryview) | `boolean` | Save a subtree of the registry to a file. |
| [`restoreKey(RegistryRoot, String, String, RegistryView)`](#restorekey-registryroot-string-string-registryview) | `boolean` | Restore a subtree of the registry from a file. |

### keyExists(RegistryRoot, String)

```java
public static boolean keyExists(RegistryRoot root, String keyName)
```

Checks if a registry key exists.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.

**Returns:** `true` if the key exists.

### createKey(RegistryRoot, String)

```java
public static boolean createKey(RegistryRoot root, String keyName)
```

Creates a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.

**Returns:** `true` if successful.

### getValue(RegistryRoot, String, String)

```java
public static Object getValue(RegistryRoot root, String keyName, String valueName)
```

Retrieves a registry value. The class of the returned object is determined
by the value's type.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `valueName` — the name of the registry value.

**Returns:** the requested value. Returns `null`, if the value doesn't exist. Otherwise
it is an instance of one of the following classes: `String, Integer, Long, String[], byte[], WinRegistry.ExpandString`.

### setValue(RegistryRoot, String, String, Object)

```java
public static boolean setValue(RegistryRoot root, String keyName, String valueName, Object value)
```

Sets a registry value. The type is determined by the class of the value.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants
- `keyName` — the name of the key without a leading backslash.
- `valueName` — the name of the registry value.
- `value` — an instance of one of the following classes: `String, Integer, Long, String[], byte[], WinRegistry.ExpandString`.

**Returns:** `true` if successful.

### deleteValue(RegistryRoot, String, String)

```java
public static void deleteValue(RegistryRoot root, String keyName, String valueName)
```

Deletes a registry value.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `valueName` — the name of the registry value.

### deleteKey(RegistryRoot, String, boolean)

```java
public static void deleteKey(RegistryRoot root, String keyName, boolean onlyIfEmpty)
```

Deletes a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `onlyIfEmpty` — if `true`, the method will delete the key only if the key contains no
values and no subkey.

### getSubKeyNames(RegistryRoot, String)

```java
public static String[] getSubKeyNames(RegistryRoot root, String keyName)
```

Retrieves the subkeys of a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.

**Returns:** an array with the subkeys' names. Returns an empty array if there are no subkeys and
`null` if the key doesn't exist or if an error occurs.

### getValueNames(RegistryRoot, String)

```java
public static String[] getValueNames(RegistryRoot root, String keyName)
```

Retrieves the exiting value names of a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.

**Returns:** an array with the values' names. Returns an empty array if there are no values and
`null` if the key doesn't exist or if an error occurs.

### saveKey(RegistryRoot, String, String)

```java
public static boolean saveKey(RegistryRoot root, String keyName, String fileName)
```

Save a subtree of the registry to a file.
The subtree can be restored with `restoreKey`.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash. This is the root of the saved subtree.
- `fileName` — the file to which the subtree should be saved.

**Returns:** whether the operation was successful or not.

**See also:**

- [WinRegistry.restoreKey](WinRegistry.md#restorekey-registryroot-string-string)

### restoreKey(RegistryRoot, String, String)

```java
public static boolean restoreKey(RegistryRoot root, String keyName, String fileName)
```

Restore a subtree of the registry from a file.
This method can restore files saved with the `saveKey` method.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash. This is the key to which the root of the saved subtree
will be restored.
- `fileName` — the file from which the saved subtree should be read.

**Returns:** whether the operation was successful or not.

**See also:**

- [WinRegistry.saveKey](WinRegistry.md#savekey-registryroot-string-string)

### keyExists(RegistryRoot, String, RegistryView)

```java
public static boolean keyExists(RegistryRoot root, String keyName, RegistryView registryView)
```

Checks if a registry key exists.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** `true` if the key exists.

### createKey(RegistryRoot, String, RegistryView)

```java
public static boolean createKey(RegistryRoot root, String keyName, RegistryView registryView)
```

Creates a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** `true` if successful.

### getValue(RegistryRoot, String, String, RegistryView)

```java
public static Object getValue(RegistryRoot root, String keyName, String valueName, RegistryView registryView)
```

Retrieves a registry value. The class of the returned object is determined
by the value's type.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `valueName` — the name of the registry value.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** the requested value. Returns `null`, if the value doesn't exist. Otherwise
it is an instance of one of the following classes: `String, Integer, Long, String[], byte[], WinRegistry.ExpandString`.

### setValue(RegistryRoot, String, String, Object, RegistryView)

```java
public static boolean setValue(RegistryRoot root, String keyName, String valueName, Object value, RegistryView registryView)
```

Sets a registry value. The type is determined by the class of the value.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants
- `keyName` — the name of the key without a leading backslash.
- `valueName` — the name of the registry value.
- `value` — an instance of one of the following classes: `String, Integer, Long, String[], byte[], WinRegistry.ExpandString`.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** `true` if successful.

### deleteValue(RegistryRoot, String, String, RegistryView)

```java
public static void deleteValue(RegistryRoot root, String keyName, String valueName, RegistryView registryView)
```

Deletes a registry value.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `valueName` — the name of the registry value.
- `registryView` — the registry view used on 64-bit systems.

### deleteKey(RegistryRoot, String, boolean, RegistryView)

```java
public static void deleteKey(RegistryRoot root, String keyName, boolean onlyIfEmpty, RegistryView registryView)
```

Deletes a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `onlyIfEmpty` — if `true`, the method will delete the key only if the key contains no
values and no subkey.
- `registryView` — the registry view used on 64-bit systems.

### getSubKeyNames(RegistryRoot, String, RegistryView)

```java
public static String[] getSubKeyNames(RegistryRoot root, String keyName, RegistryView registryView)
```

Retrieves the subkeys of a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** an array with the subkeys' names. Returns an empty array if there are no subkeys and
`null` if the key doesn't exist or if an error occurs.

### getValueNames(RegistryRoot, String, RegistryView)

```java
public static String[] getValueNames(RegistryRoot root, String keyName, RegistryView registryView)
```

Retrieves the exiting value names of a registry key.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash.
- `registryView` — the registry view used on 64-bit systems.
`null` if the key doesn't exist or if an error occurs.

**Returns:** an array with the values' names. Returns an empty array if there are no values and

### saveKey(RegistryRoot, String, String, RegistryView)

```java
public static boolean saveKey(RegistryRoot root, String keyName, String fileName, RegistryView registryView)
```

Save a subtree of the registry to a file.
The subtree can be restored with `restoreKey`.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash. This is the root of the saved subtree.
- `fileName` — the file to which the subtree should be saved.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** whether the operation was successful or not.

**See also:**

- [WinRegistry.restoreKey](WinRegistry.md#restorekey-registryroot-string-string)

### restoreKey(RegistryRoot, String, String, RegistryView)

```java
public static boolean restoreKey(RegistryRoot root, String keyName, String fileName, RegistryView registryView)
```

Restore a subtree of the registry from a file.
This method can restore files saved with the `saveKey` method.


**Parameters:**

- `root` — one of the `RegistryRoot.*` constants.
- `keyName` — the name of the key without a leading backslash. This is the key to which the root of the saved subtree
will be restored.
- `fileName` — the file from which the saved subtree should be read.
- `registryView` — the registry view used on 64-bit systems.

**Returns:** whether the operation was successful or not.

**See also:**

- [WinRegistry.saveKey](WinRegistry.md#savekey-registryroot-string-string)

