Toggle between two monitors using batch file

288 views Asked by At

I'm trying to change between my first monitor and both monitors on at the same time. When I use displayswitch.exe /internal or displayswitch.exe /extend on cmd they always work, however I cannot made this code to work inside the batch file. Can someone help me? Thx

@echo off

REM Check current display mode
powershell -command "(Get-WmiObject -Namespace root\wmi -Class WmiMonitorConnectionParams).Active"

REM Check if current mode is "Extend" or "Internal"
if "%ERRORLEVEL%"=="1" (
    REM Current mode is "Extend", switch to "Internal"
    echo Switching to Internal display mode...
    displayswitch.exe /internal
) else (
    REM Current mode is "Internal", switch to "Extend"
    echo Switching to Extend display mode...
    displayswitch.exe /extend
)

echo Display mode switched successfully.
pause
0

There are 0 answers