Change Win-10 display settings on command line or via C#

Context: Windows 10 Desktop PC "losing track" of screens, and they go/stay black

I want to mimic the effect of "changing the Windows Display config" (see end for the specific UI navigation) on a command line, so that I can set it up such that I can easily run the command/script with Keyboard only, without access to the monitors.

All I need is a script or exe that can do this, and then either I can use my keyboard's has programmable F-Keys, or I could do:

  • Win-Key
  • type "cmd"
  • Enter
  • type "reset_screens.sh/.cmd/.ps1/.exe/.whatever"
  • Enter

So, how can I reproduce the effect of that UI interaction without the UI?

UI Sequence:

  • Minimise everything down to desktop
  • Context Menu for desktop background
  • "Display Settings"
  • Scroll down to "Multiple Displays".
  • In the drop down change from "Extend these displays" to "Duplicate these display".
  • What happens after that is irrelevant, as long as it then gets reversed

Solution 1:

There is a command that can do it called: DISPLAYSWITCH.exe Note this is the program that opens when you press Windows+P

I don't know how it works internally, but you can call it from C#.

The WIN32 command for updating these display settings seems to be: SetDisplayConfig

Syntax DISPLAYSWITCH /Option

Options

   /internal    Switch to use the primary display only.
   1            All other connected displays will be disabled. 

   /clone       The primary display will be mirrored on a second screen.
   2        

   /extend      Expand the Desktop to a secondary display.
   3            This allows one desktop to span multiple displays. (Default).

   /external    Switch to the external display only (second screen).
   4            The current main display will be disabled.