Skip to content

$cs.Reg_CreateKey

Creates a registry key at the given path, automatically creating any missing parent keys along the way. If the key already exists, nothing happens.

If the key can’t be created — for example, because access is denied or regroot isn’t a supported root — the function doesn’t raise an error. The failure is only logged. Use $cs.Reg_ExistKey afterwards if the script depends on the key.

$cs.Reg_CreateKey(string regroot, string regpath)

Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, or HKU/HKEY_USERS. 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.

Registry key path to create, relative to regroot. Missing parent keys are created automatically.

None.

Terminal window
$cs.Reg_CreateKey('HKLM', 'SOFTWARE\7-Zip')

Creating a nested vendor/product key structure to hold app-specific configuration, even though none of the parent keys exist yet.

Terminal window
$cs.Reg_CreateKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Licensing')
$cs.Job_WriteLog("Created Licensing configuration key")

Creating a per-feature subkey during PostInstall so later steps can write feature-specific settings into it.

Terminal window
$cs.Reg_CreateKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting')
$cs.Reg_SetDword('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting', 'Enabled', 1)

$cs.Reg_ExistKey $cs.Reg_DelTree $cs.Reg_SetString