$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, or HKU/HKEY_USERS. Any other root, such as HKCR or HKCC, always returns $false. PowerPacks run as SYSTEM, so HKCU is the SYSTEM account’s hive, not the logged-on user’s. To change user settings, see Invoke-RunAsLoggedOnUser.
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”Under HKU, the path starts with the SID of a loaded user profile:
$userKey = "S-1-5-21-1004336348-1177238915-682003330-1001\Software\Adobe\Acrobat Reader\DC\AVGeneral"if ($cs.Reg_ExistKey("HKU", $userKey)){ $cs.Reg_SetDword("HKU", $userKey, "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")}