Skip to content

$cs.Reg_SetExpandString

Writes a REG_EXPAND_SZ registry value (a string containing unexpanded environment-variable references such as %SystemRoot%). The key is created automatically if it doesn’t exist yet.

$cs.Reg_SetExpandString(string registryroot, string regkey, string regvaluename, string regvaluedata)

Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, or HKU/HKEY_USERS.

Registry key path, relative to registryroot. Created automatically if it doesn’t exist.

Name of the value to write.

String to write, typically containing environment-variable references (e.g. %SystemRoot%\TEMP).

None.

Terminal window
$cs.Reg_SetExpandString('HKLM', 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Temp', '%SystemRoot%\TEMP')

Writing a DisplayIcon path for an Uninstall registry entry that should keep its environment-variable reference unexpanded, so it still resolves correctly on machines with a different ProgramFiles location.

Terminal window
$cs.Reg_SetExpandString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'DisplayIcon', '%ProgramFiles%\Contoso\AppSuite\AppSuite.exe')

Writing a log-directory setting that references %ProgramData%, so the application resolves it itself at runtime rather than baking in a hardcoded path.

Terminal window
$cs.Reg_SetExpandString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LogDirectory', '%ProgramData%\Contoso\AppSuite\Logs')
$cs.Job_WriteLog("Configured LogDirectory as an expandable path")

$cs.Reg_GetExpandString $cs.Reg_SetString