Skip to content

$cs.Reg_ExistKey

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

$cs.Reg_ExistKey(string registryroot, string regkey)

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

Registry key path to check for, relative to registryroot.

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

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

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

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

$cs.Reg_CreateKey $cs.Reg_DelTree $cs.Reg_ExistVariable