|
# ================================================================================================== |
|
# Script Name : Mitigate-RdpDeadlock-CU202609.ps1 |
|
# Version : 1.0.1 |
|
# Author : Michel Sijmons |
|
# License : Apache 2.0 |
|
# CanonicalURL: https://mickert.dev |
|
# |
|
# Purpose : |
|
# Mitigation workflow for the September 2026 Cumulative Update RDP regression affecting |
|
# Remote Desktop Services session stability by manipulating the Windows Feature Management |
|
# (Velocity) subsystem flags natively. |
|
# |
|
# ================================================================================================ |
|
# IMPORTANT NOTICE - UPDATED AFTER MICROSOFT'S CONTROLLED KIR RELEASE (2026-09-13 UTC) |
|
# ================================================================================================ |
|
# |
|
# Microsoft has released a Known Issue Rollback (KIR) for the September 2026 Remote Desktop |
|
# Services regression affecting Windows Server 2022. This KIR was initially distributed only |
|
# to customers with direct Microsoft support/licensing and is not publicly documented in the |
|
# standard release-health pages. |
|
# |
|
# Public references: |
|
# - Citrix support article confirming the issue: |
|
# https://support.citrix.com/external/article/CTX697101/issues-with-microsoft-windows-september.html |
|
# |
|
# - Community report with details and download links: |
|
# https://www.reddit.com/r/Action1/comments/1wcgwbw/comment/p9fxlmh/ |
|
# |
|
# Official KIR GPO download for Windows Server 2022: |
|
# https://download.microsoft.com/download/57564574-fc7f-4fdd-ba52-4ed106b8a9ac/Windows Server 2022 KB5122882 260911_18471 Known Issue Rollback.msi |
|
# |
|
# What this means: |
|
# - The Velocity/FeatureManagement override (Feature ID 3802373433) used earlier is not |
|
# reliable in all environments. |
|
# - The KIR-based GPO is now the recommended mitigation for production environments. |
|
# - This script remains available for documentation, testing, and rollback of previously |
|
# deployed overrides. |
|
# |
|
# You can still use this script to: |
|
# - Inspect existing Velocity overrides |
|
# - Apply or remove the 3802373433 override (for reference/testing) |
|
# - Roll back environments where the override was previously deployed |
|
# - Export backups of the FeatureManagement registry tree |
|
# |
|
# The official KIR should be used instead wherever possible. |
|
# |
|
# ================================================================================================ |
|
# |
|
# |
|
# Special thanks to Reddit user u/lesiromanu for early research into RDP regression behavior: |
|
# - https://www.reddit.com/user/lesiromanu/ |
|
# - https://www.reddit.com/r/sysadmin/comments/1wap96b/comment/p8wqgzy/ |
|
# |
|
# Additional thanks to Rudy Mens for the technical write-up and answers |
|
# - https://lazyadmin.nl/ |
|
# - https://lazyadmin.nl/it/september-2026-update-break-rds-how-to-fix/ |
|
# |
|
# Description : |
|
# This script performs an administrative bypass to handle the core terminal services graphics |
|
# pipeline deadlock ("Securing Remote connection"). It applies native privilege elevation |
|
# (SeRestorePrivilege) inside an embedded Win32/C# memory module to cleanly manage keys |
|
# guarded by TrustedInstaller. |
|
# |
|
# Operations executed: |
|
# - Multi-tier conflict scanning across all Feature Overrides priority layers (0..15). |
|
# - Pre-execution registry configuration state backup (.reg format). |
|
# - Embedded Win32 API layer invocation to inject the selected feature lock state. |
|
# - Deep kernel-level deletion (NtDeleteKey) to ensure successful rollback of protected containers. |
|
# - Optional task automation alignment for 'ReconcileFeatures' maintenance controls. |
|
# - Returns industry-standard exit code 3010 when reboot sequence is required. |
|
# |
|
# Notes : |
|
# - This script does NOT perform rollback of the 2026-09 CU. |
|
# - ASCII-only output for full compatibility with Action1, RMM platforms, and log parsers. |
|
# |
|
# Requirements : |
|
# - Run as Administrator / SYSTEM context |
|
# - PowerShell 5.1 or later |
|
# |
|
# Parameters & Usage : |
|
# -Priority (int) : The evaluation tier to apply the override to (0, 4, 8, 9, 15). |
|
# DEFAULT: 4 (Flighting layer, matching Microsoft default). |
|
# RECOMMENDED FOR PRODUCTION: 15 (Enterprise Policy layer to block updates). |
|
# -FeatureId (string) : Target configuration flag decimal ID. Default: "3802373433". |
|
# -Remove (switch) : Toggles script into rollback mode. Purges the custom keys and values. |
|
# -CheckOnly (switch) : Scans all priority tiers for existing configurations without making changes. |
|
# -BackupOnly (switch) : Creates a time-stamped backup of the Overrides registry tree and exits. |
|
# -DisableReconcileTask (sw) : Disables/Enables the built-in ReconcileFeatures system maintenance task. |
|
# -RebootExitCode (int) : The specific return value sent to RMM engines when a reboot is needed. Default: 3010. |
|
# |
|
# Examples: |
|
# Standard deployment (Priority 4): |
|
# .\Mitigate-RdpDeadlock-CU202609.ps1 |
|
# |
|
# Enforced production deployment with high priority override and task suspension: |
|
# .\Mitigate-RdpDeadlock-CU202609.ps1 -Priority 15 -DisableReconcileTask |
|
# |
|
# Safe state-aware rollback of mitigation on priority tier 15: |
|
# .\Mitigate-RdpDeadlock-CU202609.ps1 -Priority 15 -Remove -DisableReconcileTask |
|
# |
|
# Technical Scope & Version Warnings : |
|
# - TARGET ENVIRONMENT: This specific mitigation workflow and Feature ID (3802373433) have |
|
# been exclusively reverse-engineered and validated on WINDOWS SERVER 2022. |
|
# - UNPREDICTABLE BEHAVIOR: Applying this specific Feature ID override to other operating |
|
# system versions (including Windows Server 2019 or Windows Server 2025) is entirely |
|
# UNTESTED and may result in highly UNPREDICTABLE behavior, feature instability, or failures. |
|
# - SIDE EFFECTS: Research and validation have been restricted solely to resolving the acute |
|
# September 2026 RDS freeze/deadlock issue. Potential side effects, dependencies, or other |
|
# under-the-hood subcomponents toggled off by this feature override have NOT been evaluated. |
|
# |
|
# Registry Changes Applied by This Script : |
|
# |
|
# 1. Feature Management Override Injection |
|
# Path : HKLM\SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides\<Priority>\<FeatureId> |
|
# Values: EnabledState (DWORD) = 1 [Force Disabled] |
|
# EnabledStateOptions (DWORD) = 0 |
|
# |
|
# Purpose: |
|
# Forces the underlying Windows Feature Management pipeline to completely disable the faulty |
|
# RDP teardown/graphics path (Feature ID 3802373433) introduced in the 2026-09 updates. |
|
# Using high priority tiers ensures enforcement against background cloud-servicing updates. |
|
# |
|
# ================================================================================================== |
|
# DISCLAIMER & LICENSE |
|
# ================================================================================================== |
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
# you may not use this file except in compliance with the License. |
|
# You may obtain a copy of the License at: |
|
# |
|
# http://apache.org |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
# See the License for the specific language governing permissions and |
|
# limitations under the License. |
|
# |
|
# DISCLAIMER: |
|
# This script is provided "as-is" without any warranties or guarantees. |
|
# Use at your own risk. The author assumes no liability for any damages, |
|
# data loss, misconfiguration, or operational impact resulting from the |
|
# use of this script. Always test in a controlled environment before |
|
# deploying to production. |
|
# |
|
# ================================================================================================== |
|
# COPYRIGHT |
|
# ================================================================================================== |
|
# Copyright (c) 2026 Michel Sijmons - https://mickert.dev |
|
# All rights reserved. |
|
# ================================================================================================== |
|
Param( |
|
Param( |
|
[ValidateSet(0, 4, 8, 9, 15)] |
|
[int]$Priority = 4, |
|
[string]$FeatureId = "3802373433", |
|
[switch]$Remove, |
|
[switch]$CheckOnly, |
|
[switch]$BackupOnly, |
|
[switch]$DisableReconcileTask, |
|
[string]$BackupFolder = "C:\Windows\Logs\FeatureManagement_Backups", |
|
|
|
# Flexibele reboot exitcode parameter (default 3010) |
|
[int]$RebootExitCode = 3010 |
|
) |
|
|
|
$BaseKeyPath = "SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides" |
|
$RegistryType = @{ SZ = 1; ExpandSZ = 2; Binary = 3; DWord = 4 } |
|
|
|
$FullSubKeyPath = "$BaseKeyPath\$Priority\$FeatureId" |
|
|
|
# =================================================== |
|
# 1. EMBEDDED WIN32 KERNEL REGISTRY ENGINE |
|
# =================================================== |
|
$Definition = @" |
|
using System; |
|
using System.Text; |
|
using System.Runtime.InteropServices; |
|
|
|
public class NativeRegEngine { |
|
[DllImport("advapi32.dll", SetLastError = true)] |
|
private static extern bool OpenProcessToken(IntPtr ProcessHandle, uint DesiredAccess, out IntPtr TokenHandle); |
|
|
|
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] |
|
private static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, out LUID lpLuid); |
|
|
|
[DllImport("advapi32.dll", SetLastError = true)] |
|
private static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, uint BufferLength, IntPtr PreviousState, IntPtr ReturnLength); |
|
|
|
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] |
|
private static extern int RegCreateKeyExW(IntPtr hKey, string lpSubKey, int Reserved, string lpClass, uint dwOptions, uint samDesired, IntPtr lpSecurityAttributes, out IntPtr phkResult, out int lpdwDisposition); |
|
|
|
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] |
|
private static extern int RegSetValueExW(IntPtr hKey, string lpValueName, int Reserved, uint dwType, byte[] lpData, int cbData); |
|
|
|
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] |
|
private static extern int RegDeleteValueW(IntPtr hKey, string lpValueName); |
|
|
|
// Directe NT Kernel API import voor geforceerde verwijdering van TrustedInstaller sleutels |
|
[DllImport("ntdll.dll", CharSet = CharSet.Unicode)] |
|
private static extern int NtDeleteKey(IntPtr hKey); |
|
|
|
[DllImport("advapi32.dll", SetLastError = true)] |
|
private static extern int RegCloseKey(IntPtr hKey); |
|
|
|
[StructLayout(LayoutKind.Sequential)] |
|
private struct LUID { public uint LowPart; public int HighPart; } |
|
|
|
[StructLayout(LayoutKind.Sequential)] |
|
private struct TOKEN_PRIVILEGES { public uint PrivilegeCount; public LUID Luid; public uint Attributes; } |
|
|
|
private static readonly IntPtr HKEY_LOCAL_MACHINE = new IntPtr(unchecked((int)0x80000002)); |
|
private static readonly uint REG_OPTION_BACKUP_RESTORE = 0x00000004; |
|
private static readonly uint KEY_WRITE = 0x20006; |
|
private static readonly uint KEY_ALL_ACCESS = 0xF003F; |
|
|
|
private static void EnablePrivilege(string privilege) { |
|
IntPtr hToken; |
|
OpenProcessToken(System.Diagnostics.Process.GetCurrentProcess().Handle, 0x0020 | 0x0008, out hToken); |
|
TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES(); |
|
tp.PrivilegeCount = 1; |
|
tp.Attributes = 0x00000002; |
|
LookupPrivilegeValue(null, privilege, out tp.Luid); |
|
AdjustTokenPrivileges(hToken, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); |
|
} |
|
|
|
public static bool CreateKey(string subKeyPath) { |
|
EnablePrivilege("SeRestorePrivilege"); |
|
EnablePrivilege("SeBackupPrivilege"); |
|
IntPtr hKey; |
|
int disposition; |
|
int result = RegCreateKeyExW(HKEY_LOCAL_MACHINE, subKeyPath, 0, null, REG_OPTION_BACKUP_RESTORE, KEY_WRITE, IntPtr.Zero, out hKey, out disposition); |
|
if (result == 0) { RegCloseKey(hKey); return true; } |
|
return false; |
|
} |
|
|
|
public static bool SetAnyValue(string subKeyPath, string valueName, uint regType, byte[] rawBytes) { |
|
EnablePrivilege("SeRestorePrivilege"); |
|
EnablePrivilege("SeBackupPrivilege"); |
|
IntPtr hKey; |
|
int disposition; |
|
int result = RegCreateKeyExW(HKEY_LOCAL_MACHINE, subKeyPath, 0, null, REG_OPTION_BACKUP_RESTORE, KEY_WRITE, IntPtr.Zero, out hKey, out disposition); |
|
if (result == 0) { |
|
int setKeyResult = RegSetValueExW(hKey, valueName, 0, regType, rawBytes, rawBytes.Length); |
|
RegCloseKey(hKey); |
|
return (setKeyResult == 0); |
|
} |
|
return false; |
|
} |
|
|
|
public static bool DeleteKeyAndValues(string subKeyPath) { |
|
EnablePrivilege("SeRestorePrivilege"); |
|
EnablePrivilege("SeBackupPrivilege"); |
|
IntPtr hKey; |
|
int disposition; |
|
|
|
// Open the registry key with kernel-bypass flags |
|
int result = RegCreateKeyExW(HKEY_LOCAL_MACHINE, subKeyPath, 0, null, REG_OPTION_BACKUP_RESTORE, KEY_ALL_ACCESS, IntPtr.Zero, out hKey, out disposition); |
|
if (result == 0) { |
|
// Delete leftover values |
|
RegDeleteValueW(hKey, "EnabledState"); |
|
RegDeleteValueW(hKey, "EnabledStateOptions"); |
|
|
|
// Call NtDeleteKey on the actieve handle to let the kernel delete the container directly |
|
int ntResult = NtDeleteKey(hKey); |
|
RegCloseKey(hKey); |
|
|
|
return (ntResult == 0); |
|
} |
|
return false; |
|
} |
|
} |
|
"@ |
|
|
|
if (-not ([System.Management.Automation.PSTypeName]'NativeRegEngine').Type) { |
|
Add-Type -TypeDefinition $Definition |
|
} |
|
|
|
function Get-BytesForRegistry($Value, $Type) { |
|
switch ($Type) { |
|
"DWord" { return [BitConverter]::GetBytes([int]$Value) } |
|
"String" { return [Text.Encoding]::Unicode.GetBytes("$Value`0") } |
|
"ExpandString" { return [Text.Encoding]::Unicode.GetBytes("$Value`0") } |
|
"Binary" { return [byte[]]$Value } |
|
Default { throw "Registry data type not currently supported." } |
|
} |
|
} |
|
|
|
function Take-RegistryBackup { |
|
if (-not (Test-Path $BackupFolder)) { New-Item -ItemType Directory -Path $BackupFolder -Force | Out-Null } |
|
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss" |
|
$BackupFile = "$BackupFolder\Overrides_Backup_$Timestamp.reg" |
|
Write-Host "[INFO] Creating a complete backup of the Overrides key..." |
|
& reg.exe export "HKLM\$BaseKeyPath" "$BackupFile" /y | Out-Null |
|
} |
|
|
|
if ($BackupOnly) { |
|
Take-RegistryBackup |
|
Write-Host "[SUCCESS] Backup process finished." |
|
Exit 0 |
|
} |
|
|
|
# ========================================== |
|
# MODE 1: REMOVE / ROLLBACK OVERRIDE |
|
# ========================================== |
|
if ($Remove) { |
|
Write-Host "[INFO] Rollback mode activated. Target path: HKLM:\$FullSubKeyPath" |
|
Take-RegistryBackup |
|
if ($CheckOnly) { Write-Host "[STOP] -CheckOnly found. Exiting rollback simulation."; Exit 0 } |
|
|
|
Write-Host "[ACTION] Deleting key cleanly via NtDeleteKey Kernel bypass..." |
|
if ([NativeRegEngine]::DeleteKeyAndValues($FullSubKeyPath)) { |
|
Write-Host "[SUCCESS] Key cleared out perfectly." |
|
if ($DisableReconcileTask) { |
|
Enable-ScheduledTask -TaskName "ReconcileFeatures" -TaskPath "\Microsoft\Windows\Flighting\FeatureConfig\" | Out-Null |
|
} |
|
Write-Host "ROLLBACK COMPLETE: Reboot requested via code $RebootExitCode." |
|
Exit $RebootExitCode |
|
} else { |
|
Write-Error "[FATAL] Native engine failed to execute deletion." |
|
Exit 1 |
|
} |
|
} |
|
|
|
# ========================================== |
|
# MODE 2: APPLY / INJECT OVERRIDE (DEFAULT) |
|
# ========================================== |
|
Write-Host "[INFO] Scanning priority tiers for existing configurations..." |
|
$FoundExisting = $false |
|
foreach ($Tier in 0..15) { |
|
$ScanPath = "$BaseKeyPath\$Tier\$FeatureId" |
|
if (Test-Path "HKLM:\$ScanPath") { |
|
$FoundExisting = $true |
|
if ($CheckOnly) { |
|
$Val = Get-ItemProperty -Path "HKLM:\$ScanPath" -ErrorAction SilentlyContinue |
|
$State = if ($Val) { $Val.EnabledState } else { "" } |
|
Write-Host "[WARNING] ALERT: An override already exists at Tier $Tier! (EnabledState = $State)" |
|
} |
|
} |
|
} |
|
|
|
if ($CheckOnly) { |
|
if (-not $FoundExisting) { Write-Host "[INFO] No existing configurations found." } |
|
Exit 0 |
|
} |
|
|
|
if ($FoundExisting) { |
|
Write-Host "[STOP] Script safely exiting to prevent conflicts. No changes made." |
|
Exit 0 |
|
} |
|
|
|
try { |
|
Take-RegistryBackup |
|
Write-Host "[INFO] Processing injection..." |
|
$KeyCreated = [NativeRegEngine]::CreateKey($FullSubKeyPath) |
|
$BytesState = Get-BytesForRegistry -Value 1 -Type "DWord" |
|
$BytesOptions = Get-BytesForRegistry -Value 0 -Type "DWord" |
|
$Prop1Set = [NativeRegEngine]::SetAnyValue($FullSubKeyPath, "EnabledState", $RegistryType.DWord, $BytesState) |
|
$Prop2Set = [NativeRegEngine]::SetAnyValue($FullSubKeyPath, "EnabledStateOptions", $RegistryType.DWord, $BytesOptions) |
|
|
|
if ($KeyCreated -and $Prop1Set -and $Prop2Set) { |
|
Write-Host "[SUCCESS] Custom parameters injected flawlessly at Tier $Priority." |
|
if ($DisableReconcileTask) { |
|
Disable-ScheduledTask -TaskName "ReconcileFeatures" -TaskPath "\Microsoft\Windows\Flighting\FeatureConfig\" | Out-Null |
|
Write-Host "[SUCCESS] Maintenance task disabled." |
|
} |
|
Write-Host "SUCCESS: Mitigation applied. Reboot requested via code $RebootExitCode." |
|
Exit $RebootExitCode |
|
} else { |
|
Write-Error "[FATAL] Modular pipeline returned a failure state." |
|
Exit 1 |
|
} |
|
} catch { |
|
Write-Error "[FATAL] Execution breakdown: $_" |
|
Exit 1 |
|
} |