# WinEnvVars

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

```java
public class WinEnvVars
```

Collection of static methods to get and modify environment variables on Windows.

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`set(String, String)`](#set-string-string) | `void` | Sets a global environment variable. |
| [`setUserSpecific(String, String)`](#setuserspecific-string-string) | `void` | Sets a user-specific environment variable. |
| [`getenv(String)`](#getenv-string) | `String` | Returns a single environment variable. |
| [`getenv()`](#getenv) | `Properties` | Returns all environment variables. |
| [`getFromRegistry(String, boolean)`](#getfromregistry-string-boolean) | `String` | Return an environment variable as set in the Windows registry. |
| [`appendToPath(String)`](#appendtopath-string) | `void` | Appends one or more directories to the PATH environment variable. |
| [`prependToPath(String)`](#prependtopath-string) | `void` | Prepends one or more directories to the PATH environment variable. |
| [`appendToUserPath(String)`](#appendtouserpath-string) | `void` | Appends one or more directories to the user-specific PATH environment variable. |
| [`prependToUserPath(String)`](#prependtouserpath-string) | `void` | Prepends one or more directories to the user-specific PATH environment variable. |

### set(String, String)

```java
public static void set(String key, String value) throws IOException
```

Sets a global environment variable. Needs Administrator rights.


**Parameters:**

- `key` — the name of the environment variable
- `value` — the value of the environment variable

**Throws:**

- `IOException` — if the environment variable could not be set

### setUserSpecific(String, String)

```java
public static void setUserSpecific(String key, String value) throws IOException
```

Sets a user-specific environment variable.


**Parameters:**

- `key` — the name of the environment variable
- `value` — the value of the environment variable

**Throws:**

- `IOException` — if the environment variable could not be set

### getenv(String)

```java
public static String getenv(String key)
```

Returns a single environment variable.


**Parameters:**

- `key` — the name of the environment variable. Case does not matter.

**Returns:** the value of the environment variable or `null` if not defined

### getenv()

```java
public static Properties getenv()
```

Returns all environment variables.


**Returns:** a property map with all environment variables and their values

### getFromRegistry(String, boolean)

```java
public static String getFromRegistry(String key, boolean userSpecific) throws IOException
```

Return an environment variable as set in the Windows registry. The user-specific setting may be different
from the value returned in [`WinEnvVars.getenv`](WinEnvVars.md#getenv). For example, the `PATH` environment variable is modified
by the install4j launcher and is not equal to the system setting. In addition, the value returned for
`PATH` will have no variable substitutions performed.


**Parameters:**

- `key` — the name of the environment variable. Case does not matter.
- `userSpecific` — If `true` the user-specific variant should be retrieved. Otherwise, the global setting
will be returned.

**Returns:** the value of the environment variable or `null` if not defined

**Throws:**

- `IOException` — if the environment variable could not be retrieved

### appendToPath(String)

```java
public static void appendToPath(String value) throws IOException
```

Appends one or more directories to the PATH environment variable. Needs Administrator rights.


**Parameters:**

- `value` — the value to be appended to the path

**Throws:**

- `IOException` — if the environment variable could not be set

### prependToPath(String)

```java
public static void prependToPath(String value) throws IOException
```

Prepends one or more directories to the PATH environment variable. Needs Administrator rights.


**Parameters:**

- `value` — the value to be prepended to the path

**Throws:**

- `IOException` — if the environment variable could not be set

### appendToUserPath(String)

```java
public static void appendToUserPath(String value) throws IOException
```

Appends one or more directories to the user-specific PATH environment variable.


**Parameters:**

- `value` — the value to be appended to the path

**Throws:**

- `IOException` — if the environment variable could not be set

**See also:**

- [WinEnvVars.appendToPath](WinEnvVars.md#appendtopath-string)

### prependToUserPath(String)

```java
public static void prependToUserPath(String value) throws IOException
```

Prepends one or more directories to the user-specific PATH environment variable.


**Parameters:**

- `value` — the value to be prepended to the path

**Throws:**

- `IOException` — if the environment variable could not be set

**See also:**

- [WinEnvVars.prependToPath](WinEnvVars.md#prependtopath-string)

## Constructors

| Signature | Description |
|---|---|
| [`WinEnvVars()`](#winenvvars) |  |

### WinEnvVars()

```java
public WinEnvVars()
```

