From 2b237bb8b3d9ef95ef18023053285461b18fc2e7 Mon Sep 17 00:00:00 2001 From: Guofang Date: Wed, 28 Oct 2026 15:06:08 +0800 Subject: [PATCH] Add a tool to switch the Windows display scale between 100% and 200% 81-Toggle-Scale.ps1 writes LogPixels, Win8DpiScaling and AppliedDPI for the current user; the change needs a restart, so the .bat launcher offers to restart at the end. It is picked up by the existing NN-*.bat/.ps1 globs and copied to Desktop\Tools. Co-Authored-By: Claude Sonnet 5.5 --- seediso/windows11/81-Toggle-Scale.bat | 21 +++++++++++++++++ seediso/windows11/81-Toggle-Scale.ps1 | 34 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 seediso/windows11/81-Toggle-Scale.bat create mode 100644 seediso/windows11/81-Toggle-Scale.ps1 diff --git a/seediso/windows11/81-Toggle-Scale.bat b/seediso/windows11/81-Toggle-Scale.bat new file mode 100644 index 0000000..502a200 --- /dev/null +++ b/seediso/windows11/81-Toggle-Scale.bat @@ -0,0 +1,21 @@ +@echo off +setlocal +title Toggle display scale + +rem No argument: switch between 100% and 200%. Pass 100 or 200 to force a value. +rem Runs as the current user (no elevation), because the scale is a per-user setting. +rem The change takes effect after a restart; the script offers to restart at the end. + +set "SCALE=%~1" +if not defined SCALE set "SCALE=0" + +powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp081-Toggle-Scale.ps1" -Scale %SCALE% +if errorlevel 1 ( + pause + exit /b 1 +) + +echo. +choice /c YN /m "Restart now" +if errorlevel 2 exit /b 0 +shutdown.exe /r /t 5 diff --git a/seediso/windows11/81-Toggle-Scale.ps1 b/seediso/windows11/81-Toggle-Scale.ps1 new file mode 100644 index 0000000..1796f7a --- /dev/null +++ b/seediso/windows11/81-Toggle-Scale.ps1 @@ -0,0 +1,34 @@ +# Switches the display scale between 100% and 200% for the current user. +# With no argument it toggles; -Scale 100 or -Scale 200 forces a value. +# The scale is stored in the registry (LogPixels), so the change takes effect only after +# a restart. Use -Restart to reboot right away. +param( + [ValidateSet(0, 100, 200)] + [int]$Scale = 0, + [switch]$Restart +) + +$ErrorActionPreference = 'Stop' + +$desktopKey = 'HKCU:\Control Panel\Desktop' +$metricsKey = 'HKCU:\Control Panel\Desktop\WindowMetrics' + +$logPixels = (Get-ItemProperty -Path $desktopKey -Name LogPixels -ErrorAction SilentlyContinue).LogPixels +if (-not $logPixels) { $logPixels = 96 } +$current = [int][math]::Round($logPixels * 100 / 96) + +$target = if ($Scale -ne 0) { $Scale } elseif ($current -eq 100) { 200 } else { 100 } +$dpi = [int]($target * 96 / 100) + +Write-Host "Scale: $current% -> $target%" + +# Win8DpiScaling=1 makes Windows use LogPixels instead of the per-monitor recommendation. +Set-ItemProperty -Path $desktopKey -Name LogPixels -Type DWord -Value $dpi +Set-ItemProperty -Path $desktopKey -Name Win8DpiScaling -Type DWord -Value 1 +Set-ItemProperty -Path $metricsKey -Name AppliedDPI -Type DWord -Value $dpi + +Write-Host 'Restart Windows for the new scale to take effect.' +if ($Restart) { + Write-Host 'Restarting in 5 seconds...' + shutdown.exe /r /t 5 +}