# $cs.Reg_EnumKey

> Returns the names of the subkeys found directly under a registry key. If the path doesn't exist or has no subkeys, an empty result is returned rather than throwing.

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

### Description

Returns the names of the subkeys found directly under a registry key. If the path doesn't exist or has no subkeys, an empty result is returned rather than throwing.

### Syntax

$cs.Reg_EnumKey(string regroot, string regpath, bool mustexist)

### Parameters

#### regroot (String)

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

#### regpath (String)

Registry key path to enumerate, relative to `regroot`.

#### mustexist (Boolean)

Accepted for signature compatibility but currently has no effect on behavior — the function does not throw or change behavior based on this value.

### Return value

Array of subkey names (`string[]`). Empty if the path doesn't exist or has no subkeys.

### Example

**PowerShell**

```powershell
$regkeys = $cs.Reg_EnumKey('HKLM', 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', $true)
foreach ($item in $regkeys) {
    $cs.Job_WriteLog("Regkey found: $item")
}
```

Enumerating installed version subkeys under a vendor key during `Uninstall`, so old versions can be identified and removed one by one.

```powershell
$versions = $cs.Reg_EnumKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Versions', $true)
foreach ($version in $versions) {
    if ($version -ne '5.2.0') {
        $cs.Job_WriteLog("Removing outdated version key: $version")
        $cs.Reg_DelTree('HKLM', "SOFTWARE\Contoso\AppSuite\Versions\$version")
    }
}
```

Checking how many components are registered under a key before deciding whether the whole feature tree should be torn down.

```powershell
$components = $cs.Reg_EnumKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Components', $true)
if ($components.Count -eq 0) {
    $cs.Job_WriteLog("No components left, removing AppSuite root key")
    $cs.Reg_DelTree('HKLM', 'SOFTWARE\Contoso\AppSuite')
}
```

### Related functions

[$cs.Reg_ExistKey](/capainstaller/powerpacks/cs-reg-existkey/) [$cs.Reg_GetString](/capainstaller/powerpacks/cs-reg-getstring/)
