Skip to content

$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.

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

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

Registry key path to enumerate, relative to regroot.

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

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

Terminal window
$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.

Terminal window
$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.

Terminal window
$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')
}

$cs.Reg_ExistKey $cs.Reg_GetString