Skip to content

$cs.Reg_GetString

Reads a REG_SZ (string) registry value. Returns an empty string "" if the value isn’t found — never $null.

$cs.Reg_GetString(string registryroot, string regkey, string regvalue)

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

Registry key path containing the value, relative to registryroot.

Name of the value to retrieve. Pass "" for the key’s default value.

String. Empty string "" if the value isn’t found.

Terminal window
$filepath = $cs.Reg_GetString("HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe", "")
if ($filepath -ne "")
{
$cs.Job_WriteLog("Found 7-Zip at: $filepath")
}

Reading the DisplayVersion from an application’s Uninstall key to check whether the installed version is current.

Terminal window
$displayVersion = $cs.Reg_GetString('HKLM', 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Contoso AppSuite', 'DisplayVersion')
$cs.Job_WriteLog("Currently installed version: $displayVersion")
if ($displayVersion -eq '4.8.1')
{
$cs.Job_WriteLog("Latest version is already installed")
}

Reading a value that returns "" when not configured, and falling back to a sensible default instead of leaving it blank.

Terminal window
$logLevel = $cs.Reg_GetString('HKLM', 'SOFTWARE\Contoso\AppSuite', 'LogLevel')
if ($logLevel -eq '')
{
$logLevel = 'Info'
}
$cs.Job_WriteLog("Using log level: $logLevel")

$cs.Reg_SetString $cs.Reg_ExistVariable $cs.Reg_DeleteVariable