# $cs.Reg_GetString

> Reads a REG_SZ (string) registry value. Returns an empty string "" if the value isn't found — never $null.

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

### Description

Reads a `REG_SZ` (string) registry value. Returns an empty string `""` if the value isn't found — never `$null`.

### Syntax

$cs.Reg_GetString(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. Empty string `""` if the value isn't found.

### Example

**PowerShell**

```powershell
$filepath = $cs.Reg_GetString("HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe", "")
if ($filepath -ne "")
{
    $cs.Job_WriteLog("Found 7-Zip at: $filepath")
}
```

Reading the `DisplayVersion` from an application's Uninstall key to check whether the installed version is current.

```powershell
$displayVersion = $cs.Reg_GetString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'DisplayVersion')
$cs.Job_WriteLog("Currently installed version: $displayVersion")
if ($displayVersion -eq '4.8.1')
{
    $cs.Job_WriteLog("Latest version is already installed")
}
```

Reading a value that returns `""` when not configured, and falling back to a sensible default instead of leaving it blank.

```powershell
$logLevel = $cs.Reg_GetString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LogLevel')
if ($logLevel -eq '')
{
    $logLevel = 'Info'
}
$cs.Job_WriteLog("Using log level: $logLevel")
```

### Related functions

[$cs.Reg_SetString](/capainstaller/powerpacks/cs-reg-setstring/) [$cs.Reg_ExistVariable](/capainstaller/powerpacks/cs-reg-existvariable/) [$cs.Reg_DeleteVariable](/capainstaller/powerpacks/cs-reg-deletevariable/)
