Skip to content

$cs.Reg_GetInteger

Reads a numeric (DWORD/QWORD) registry value. Returns a nullable long, so $null is returned if the value doesn’t exist or can’t be parsed as a number — always check for $null before using the result.

A REG_SZ value that contains only a number is also returned as a number. REG_DWORD values above 2147483647 (0x7FFFFFFF) are returned as negative numbers — for example, 0xFFFFFFFF is returned as -1.

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

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 containing the value, relative to registryroot.

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

Nullable long. $null if the value doesn’t exist or isn’t numeric.

Terminal window
$enable64Bit = $cs.Reg_GetInteger('HKLM', 'SOFTWARE\Microsoft\.NETFramework', 'Enable64Bit')
if ($null -ne $enable64Bit -and $enable64Bit -eq 1)
{
$cs.Job_WriteLog("64-bit JIT is enabled")
}

Reading a version-as-DWORD marker written by a previous install and comparing it against the version being installed now, guarding against $null when the marker was never set.

Terminal window
$installedBuild = $cs.Reg_GetInteger('HKLM', 'SOFTWARE\Contoso\AppSuite', 'BuildNumber')
if ($null -eq $installedBuild)
{
$cs.Job_WriteLog("No previous build recorded, treating as a fresh install")
}
elseif ($installedBuild -lt 4500)
{
$cs.Job_WriteLog("Upgrading from build $installedBuild")
}

Reading a feature-flag DWORD to decide whether an optional install step should run.

Terminal window
$reportingEnabled = $cs.Reg_GetInteger('HKLM', 'SOFTWARE\Contoso\AppSuite\Features\Reporting', 'Enabled')
if ($reportingEnabled -eq 1)
{
$cs.Job_WriteLog("Reporting feature is enabled, installing reporting components")
}

$cs.Reg_SetDword $cs.Reg_SetQword $cs.Reg_GetString