# $cs.Reg_SetExpandString

> Writes a REG_EXPAND_SZ registry value (a string containing unexpanded environment-variable references such as %SystemRoot%).

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-reg-setexpandstring/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Writes a `REG_EXPAND_SZ` registry value (a string containing unexpanded environment-variable references such as `%SystemRoot%`). The key is created automatically if it doesn't exist yet.

### Syntax

$cs.Reg_SetExpandString(string registryroot, string regkey, string regvaluename, string regvaluedata)

### Parameters

#### registryroot (String)

Root hive: `HKLM`/`HKEY_LOCAL_MACHINE`, `HKCU`/`HKEY_CURRENT_USER`, or `HKU`/`HKEY_USERS`.

#### regkey (String)

Registry key path, relative to `registryroot`. Created automatically if it doesn't exist.

#### regvaluename (String)

Name of the value to write.

#### regvaluedata (String)

String to write, typically containing environment-variable references (e.g. `%SystemRoot%\TEMP`).

### Return value

None.

### Example

**PowerShell**

```powershell
$cs.Reg_SetExpandString('HKLM', 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Temp', '%SystemRoot%\TEMP')
```

Writing a `DisplayIcon` path for an Uninstall registry entry that should keep its environment-variable reference unexpanded, so it still resolves correctly on machines with a different `ProgramFiles` location.

```powershell
$cs.Reg_SetExpandString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'DisplayIcon', '%ProgramFiles%\Contoso\AppSuite\AppSuite.exe')
```

Writing a log-directory setting that references `%ProgramData%`, so the application resolves it itself at runtime rather than baking in a hardcoded path.

```powershell
$cs.Reg_SetExpandString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LogDirectory', '%ProgramData%\Contoso\AppSuite\Logs')
$cs.Job_WriteLog("Configured LogDirectory as an expandable path")
```

### Related functions

[$cs.Reg_GetExpandString](/capainstaller/powerpacks/cs-reg-getexpandstring/) [$cs.Reg_SetString](/capainstaller/powerpacks/cs-reg-setstring/)
