# $cs.Reg_GetExpandString

> Reads a REG_EXPAND_SZ registry value.

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

### Description

Reads a `REG_EXPAND_SZ` registry value. Despite the name, it does **not** expand embedded environment variables like `%ProgramFiles%` in the returned value — it returns the raw stored string. Use `[Environment]::ExpandEnvironmentVariables($value)` if you need the expanded form. Returns an empty string if the value isn't found.

### Syntax

$cs.Reg_GetExpandString(string registryroot, string regkey, string regvalue)

### Parameters

#### registryroot (String)

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

#### regkey (String)

Registry key path containing the value, relative to `registryroot`.

#### regvalue (String)

Name of the value to retrieve. Pass `""` for the key's default value.

### Return value

String — the raw, unexpanded value. Empty string `""` if the value isn't found.

### Example

**PowerShell**

```powershell
$rawPath = $cs.Reg_GetExpandString("HKU", ".DEFAULT\Environment", "Path")
$expandedPath = [Environment]::ExpandEnvironmentVariables($rawPath)
$cs.Job_WriteLog("Expanded PATH: $expandedPath")
```

Reading an uninstall string that contains an unexpanded `%ProgramFiles%` reference, then expanding it manually so it can be invoked directly.

```powershell
$uninstallString = $cs.Reg_GetExpandString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'UninstallString')
$expandedUninstallString = [Environment]::ExpandEnvironmentVariables($uninstallString)
$cs.Job_WriteLog("Resolved uninstall command: $expandedUninstallString")
```

Reading a `DisplayIcon` value that references `%SystemRoot%`, to confirm the target file actually exists on disk after expansion.

```powershell
$rawIcon = $cs.Reg_GetExpandString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'DisplayIcon')
$expandedIcon = [Environment]::ExpandEnvironmentVariables($rawIcon)
if (-not (Test-Path $expandedIcon))
{
    $cs.Job_WriteLog("Warning: DisplayIcon target not found at $expandedIcon")
}
```

### Related functions

[$cs.Reg_SetExpandString](/capainstaller/powerpacks/cs-reg-setexpandstring/) [$cs.Reg_GetString](/capainstaller/powerpacks/cs-reg-getstring/)
