Toggle Windows High Contrast Mode Using Registry

This article explains how to programmatically enable or disable High Contrast mode in Windows by modifying specific keys in the Windows Registry. You will learn the exact Registry paths, the required flag values, and how to apply the changes immediately using a script so that the operating system updates without requiring a reboot or logoff.

Registry Location and Values

Windows stores the user settings for High Contrast in the current user hive:

The two primary values responsible for controlling High Contrast mode are:

  1. Flags (Type: REG_SZ): A string representing bit flags.
    • Disabled: 126 (Hex 0x7E)
    • Enabled: 127 (Hex 0x7F)
    • Note: The least significant bit (0x00000001 or HCF_HIGHCONTRASTON) determines whether High Contrast is active.
  2. High Contrast Scheme (Type: REG_SZ): The name of the color scheme to apply.
    • Common values: "High Contrast Black", "High Contrast White", "High Contrast #1", or "High Contrast #2".

Modifying the Registry via Command Line

To enable High Contrast mode via the command prompt:

reg add "HKCU\Control Panel\Accessibility\HighContrast" /v "Flags" /t REG_SZ /d "127" /f
reg add "HKCU\Control Panel\Accessibility\HighContrast" /v "High Contrast Scheme" /t REG_SZ /d "High Contrast Black" /f

To disable High Contrast mode:

reg add "HKCU\Control Panel\Accessibility\HighContrast" /v "Flags" /t REG_SZ /d "126" /f

Applying Changes Programmatically

Directly modifying Registry keys writes the data to disk, but Windows caches accessibility parameters in memory. To force Windows to read the updated Registry keys and apply the changes instantly, you must call the SystemParametersInfo Windows API with the SPI_SETHIGHCONTRAST (0x0043) action code.

Below is a complete PowerShell script that alters the Registry values and triggers the immediate system refresh:

$signature = @"
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref HIGHCONTRAST pvParam, uint fWinIni);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct HIGHCONTRAST {
    public uint cbSize;
    public uint dwFlags;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string lpszDefaultScheme;
}
"@

$type = Add-Type -MemberDefinition $signature -Name "Win32HighContrast" -Namespace "Accessibility" -PassThru

function Set-HighContrast {
    param (
        [bool]$Enable,
        [string]$Scheme = "High Contrast Black"
    )

    $regPath = "HKCU:\Control Panel\Accessibility\HighContrast"
    
    # 0x7F (127) for enabled, 0x7E (126) for disabled
    $flags = if ($Enable) { "127" } else { "126" }
    
    # Update the Registry
    Set-ItemProperty -Path $regPath -Name "Flags" -Value $flags
    if ($Enable) {
        Set-ItemProperty -Path $regPath -Name "High Contrast Scheme" -Value $Scheme
    }

    # Broadcast system parameter change to apply immediately
    $struct = New-Object Accessibility.Win32HighContrast+HIGHCONTRAST
    $struct.cbSize = [System.Runtime.InteropServices.Marshal]::SizeOf($struct)
    $struct.dwFlags = if ($Enable) { 0x00000001 } else { 0x00000000 }
    $struct.lpszDefaultScheme = if ($Enable) { $Scheme } else { "" }

    # SPI_SETHIGHCONTRAST = 0x0043, SPIF_UPDATEINIFILE = 0x01, SPIF_SENDCHANGE = 0x02
    [Accessibility.Win32HighContrast]::SystemParametersInfo(0x0043, $struct.cbSize, [ref]$struct, 0x03)
}

# Example usage:
# Set-HighContrast -Enable $true -Scheme "High Contrast Black"
# Set-HighContrast -Enable $false