$cs.Reg_CreateKey
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”$cs.Reg_CreateKey(string regroot, string regpath)
Parameters
Section titled “Parameters”regroot (String)
Section titled “regroot (String)”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.
regpath (String)
Section titled “regpath (String)”Registry key path to create, relative to regroot. Missing parent keys are created automatically.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$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.
$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.
$cs.Reg_CreateKey('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting')$cs.Reg_SetDword('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting', 'Enabled', 1)