windowscmdnircmd

Is there any way to check which monitor is the primary display, then execute a command based off of that in windows command line?


I'm using nircmd to change my primary display between my first and second monitor by using two batch files on my desktop; one to set primary display to the first monitor, and the other to set primary display to the second.

I was wondering if there was a way to check which display is the current primary display and then based off that result, change the display to the other one. In essence, I want to combine the two batch files into one so that I can switch displays with one file.


Solution

  • Thanks to Alex K. If anyone else wanted to do something like this, here's what the code looks like (I'm sure there's a better way to do it).

    I just created a folder that holds the empty text file that determines which monitor is the current primary display. FILEPATH is the path to that folder.

    IF EXIST FILEPATH\test.txt ( nircmd.exe setprimarydisplay 2 cd c:\\ cd FILEPATH del test.txt ) ELSE ( nircmd.exe setprimarydisplay 1 cd c:\\ cd FILEPATH echo.> test.txt )

    If anyone else stumbles upon this, feel free to ask for specifics.