Advertisement
BlueSquares

Windows 11 Batch File to Toggle/Switch Between Extend Display and Second Display

May 2nd, 2025
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.39 KB | Software | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3.  
  4. :: Script to toggle between Extend mode and Second Display Only mode
  5. :: Created by Claude - May 2, 2025
  6.  
  7. title Display Mode Toggle
  8.  
  9. echo Checking current display configuration...
  10.  
  11. :: Use DisplaySwitch command to detect current display mode
  12. for /f "tokens=*" %%a in ('powershell -command "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Screen]::AllScreens.Count"') do set screen_count=%%a
  13.  
  14. if %screen_count% LEQ 1 (
  15.     echo Only one display detected or display is in single display mode.
  16.     echo Attempting to switch to extended mode...
  17.     DisplaySwitch.exe /extend
  18.     echo Display mode changed to: EXTEND
  19.     goto :end
  20. )
  21.  
  22. :: Check if the display is currently extended
  23. :: We'll use a PowerShell command to check the current display state
  24. powershell -command "$displays = Get-WmiObject -Namespace root\wmi -Class WmiMonitorBasicDisplayParams; if($displays.Count -gt 1) { exit 0 } else { exit 1 }"
  25.  
  26. if %errorlevel% EQU 0 (
  27.     echo Current Display Mode: EXTEND
  28.     echo Switching to Second Display Only...
  29.     DisplaySwitch.exe /external
  30.     echo Display mode changed to: SECOND DISPLAY ONLY
  31. ) else (
  32.     echo Current Display Mode: SECOND DISPLAY ONLY
  33.     echo Switching to Extend...
  34.     DisplaySwitch.exe /extend
  35.     echo Display mode changed to: EXTEND
  36. )
  37.  
  38. :end
  39. echo.
  40. echo Operation completed.
  41. timeout /t 3 > nul
  42. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement