Last active
January 7, 2026 04:36
-
-
Save 5j9/98166702dd13736be436e8083b5a3045 to your computer and use it in GitHub Desktop.
Automates the fix for Windows windows resizing/shrinking to the top-left corner after the monitor sleeps. Dynamically detects current resolution and applies it to the "Simulated" and "NOEDID" registry profiles under GraphicsDrivers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run this script as Administrator to fix the "DisplayPort/Sleep Resizing" bug. | |
| # It syncs your active resolution with the Windows 'Simulated' fallback profiles. | |
| # Check for Administrator privileges | |
| if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
| Write-Warning "Please run this script as an Administrator!" | |
| break | |
| } | |
| # 1. Get current screen resolution automatically | |
| $display = Get-CimInstance Win32_VideoController | Where-Object { $_.CurrentHorizontalResolution -ne $null } | Select-Object -First 1 | |
| $currentX = $display.CurrentHorizontalResolution | |
| $currentY = $display.CurrentVerticalResolution | |
| $stride = ($currentX * 32 + 7) / 8 | |
| Write-Host "Detected Current Resolution: $($currentX)x$($currentY)" -ForegroundColor Cyan | |
| # 2. Define the Registry path | |
| $basePath = "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration" | |
| # 3. Find and update SIMULATED or NOEDID keys | |
| $keys = Get-ChildItem -Path $basePath | Where-Object { $_.PSChildName -like "*SIMULATED*" -or $_.PSChildName -like "*NOEDID*" } | |
| if ($null -eq $keys) { | |
| Write-Host "No simulated display keys found." -ForegroundColor Yellow | |
| } else { | |
| foreach ($key in $keys) { | |
| # Using joins to ensure paths are never null | |
| $p1 = Join-Path -Path $key.PSPath -ChildPath "00" | |
| $p2 = Join-Path -Path $p1 -ChildPath "00" | |
| Write-Host "Applying fix to: $($key.PSChildName)" -ForegroundColor Green | |
| # Update/Create first level (00) | |
| if (-not (Test-Path $p1)) { New-Item -Path $p1 -Force | Out-Null } | |
| Set-ItemProperty -Path $p1 -Name "PrimSurfSize.cx" -Value $currentX -Type DWord | |
| Set-ItemProperty -Path $p1 -Name "PrimSurfSize.cy" -Value $currentY -Type DWord | |
| Set-ItemProperty -Path $p1 -Name "Stride" -Value $stride -Type DWord | |
| # Update/Create second level (00\00) | |
| if (-not (Test-Path $p2)) { New-Item -Path $p2 -Force | Out-Null } | |
| Set-ItemProperty -Path $p2 -Name "ActiveSize.cx" -Value $currentX -Type DWord | |
| Set-ItemProperty -Path $p2 -Name "ActiveSize.cy" -Value $currentY -Type DWord | |
| } | |
| Write-Host "`nSuccess! Changes applied without errors." -ForegroundColor White -BackgroundColor Green | |
| Write-Host "Please restart your computer for changes to take effect." | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment