Can I create a batch file to duplicate display on monitors 1 and 2 in multi monitor setup?

t3chgr0g 1 Reputation point
2021-11-18T15:08:06.847+00:00

I work in a school where teachers have docking stations for their laptops.
They open their laptop up then have a 2nd external monitor. Then I have it set up to mirror one of those two displays onto their projector/smart board.

To achieve this I start with setting the projection options to Extend (I know I can do this part with a bat file by putting %windir%\System32\DisplaySwitch.exe /extend in it) then go to windows native display settings, choose monitor 1 and then choose duplicate this display on 1 and 2.
It is easy for me.
Not easy for 90 teachers in the building when the settings don't stick.

I'm wondering if a bat file could do:
%windir%\System32\DisplaySwitch.exe /extend then
(duplicate display 1 and 2)

Using any 3rd party utilities won't work, it'd have to be built in functionality.

Windows for business Windows Client for IT Pros User experience Other
{count} votes

1 answer

Sort by: Most helpful
  1. Khaled Elsayed Mohamed 1,335 Reputation points
    2023-06-11T12:14:58.9466667+00:00

    Hi t3chgr0g

    @echo off
    
    REM Set the display mode to duplicate on monitors 1 and 2
    echo Selecting duplicate display mode...
    DisplaySwitch.exe /clone
    
    REM Optional: Add a pause to view the result
    pause
    
    
    • Save the file with a .bat extension (e.g., duplicate_displays.bat).
    • Double-click the batch file to execute it.

    When you run the batch file, it will set the display mode to duplicate, effectively mirroring the content on monitors 1 and 2. The DisplaySwitch.exe /clone command is used to accomplish this. If you want to view the result before the batch file exits, you can uncomment the pause command by removing the REM at the beginning of the line.

    Note that the DisplaySwitch.exe utility is a built-in command-line tool in Windows that allows you to control the display settings. By using it with the /clone switch, you can duplicate the display on multiple monitors.

    Remember to adjust the batch file and display settings accordingly if you have more than two monitors or if your monitor numbering differs from the default configuration.


    another answer by using PowerShell:

    import the Win32_Monitor WMI class
    import-module win32
    Get the list of all monitors
    $monitors = get-wmiobject win32_monitor
    Get the names of monitors 1 and 2
    $monitor1 = $monitors[0].name $monitor2 = $monitors[1].name
    Duplicate the display on monitors 1 and 2
    (Get-WmiObject Win32_VideoController).SetDisplayConfig([Microsoft.Win32.SystemParametersInfo]::EnumDisplaySettings.Extend, $monitor1, $monitor2)
    

    This script will first import the Win32_Monitor WMI class. This class provides information about all monitors on the system. The script will then get the list of all monitors and get the names of monitors 1 and 2. Finally, the script will duplicate the display on monitors 1 and 2 by calling the SetDisplayConfig method on the Win32_VideoController WMI class.

    Here is a more detailed explanation of the script:

    • import-module win32 imports the Win32_Monitor WMI class.
    • get-wmiobject win32_monitor gets the list of all monitors.
    • $monitors[0].name gets the name of monitor 1.
    • $monitors[1].name gets the name of monitor 2.
    • (Get-WmiObject Win32_VideoController).SetDisplayConfig([Microsoft.Win32.SystemParametersInfo]::EnumDisplaySettings.Extend, $monitor1, $monitor2) calls the SetDisplayConfig method on the Win32_VideoController WMI class to duplicate the display on monitors 1 and 2.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.