1

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
1
  • 2
    The first thing I'd ask is that you perform a couple of tests, (under different modes), using just 1. @%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "(Get-WmiObject -Namespace root\wmi -Class WmiMonitorConnectionParams).Active" and 2. @Echo %ErrorLevel%& Pause. My best guess, regardless of the current mode, is that the ErrorLevel will always be 0, as it is returning that the powershell.exe was run successfully, not what the result of the -Command was. Commented Jun 3, 2023 at 19:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.