$cs.Reg_SetExpandString
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”$cs.Reg_SetExpandString(string registryroot, string regkey, string regvaluename, string regvaluedata)
Parameters
Section titled “Parameters”registryroot (String)
Section titled “registryroot (String)”Root hive: HKLM/HKEY_LOCAL_MACHINE, HKCU/HKEY_CURRENT_USER, or HKU/HKEY_USERS.
regkey (String)
Section titled “regkey (String)”Registry key path, relative to registryroot. Created automatically if it doesn’t exist.
regvaluename (String)
Section titled “regvaluename (String)”Name of the value to write.
regvaluedata (String)
Section titled “regvaluedata (String)”String to write, typically containing environment-variable references (e.g. %SystemRoot%\TEMP).
Return value
Section titled “Return value”None.
Example
Section titled “Example”$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.
$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.
$cs.Reg_SetExpandString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LogDirectory', '%ProgramData%\Contoso\AppSuite\Logs')$cs.Job_WriteLog("Configured LogDirectory as an expandable path")