# $cs.Reg_ExistKey

> Checks whether a registry key exists. Never throws for a missing key — it simply returns $false.

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

### Description

Checks whether a registry key exists. Never throws for a missing key — it simply returns `$false`.

### Syntax

$cs.Reg_ExistKey(string registryroot, string regkey)

### Parameters

#### registryroot (String)

Root hive: `HKLM`/`HKEY_LOCAL_MACHINE`, `HKCU`/`HKEY_CURRENT_USER`, `HKU`/`HKEY_USERS` (also accepts `HKCR` and `HKCC`).

#### regkey (String)

Registry key path to check for, relative to `registryroot`.

### Return value

Boolean — `$true` if the key exists, otherwise `$false`.

### Example

**PowerShell**

```powershell
if ($cs.Reg_ExistKey("HKU", "Software\Adobe\Acrobat Reader\DC\AVGeneral"))
{
    $cs.Reg_SetDword("HKU", "Software\Adobe\Acrobat Reader\DC\AVGeneral", "bisFirstLaunch", 0)
}
```

A `PreInstall` check to see whether the application is already installed, based on the presence of its registry footprint, and skip a redundant install.

```powershell
if ($cs.Reg_ExistKey('HKLM', 'SOFTWARE\Contoso\AppSuite'))
{
    Exit-PSScript -exitcode 3330 -exitmessage "AppSuite is already installed, skipping installation"
}
```

Skipping cleanup work during `Uninstall` when the key was never created in the first place, avoiding unnecessary log noise.

```powershell
if ($cs.Reg_ExistKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting'))
{
    $cs.Reg_DelTree('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting')
}
else
{
    $cs.Job_WriteLog("Reporting feature key not present, nothing to clean up")
}
```

### Related functions

[$cs.Reg_CreateKey](/capainstaller/powerpacks/cs-reg-createkey/) [$cs.Reg_DelTree](/capainstaller/powerpacks/cs-reg-deltree/) [$cs.Reg_ExistVariable](/capainstaller/powerpacks/cs-reg-existvariable/)
