$cs.Reg_ExistKey
Description
Section titled “Description”Checks whether a registry key exists. Never throws for a missing key — it simply returns $false.
Syntax
Section titled “Syntax”$cs.Reg_ExistKey(string registryroot, string regkey)
Parameters
Section titled “Parameters”registryroot (String)
Section titled “registryroot (String)”Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, HKU/HKEY_USERS (also accepts HKCR and HKCC).
regkey (String)
Section titled “regkey (String)”Registry key path to check for, relative to registryroot.
Return value
Section titled “Return value”Boolean — $true if the key exists, otherwise $false.
Example
Section titled “Example”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.
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.
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")}