“Extend my Windows desktop onto this monitor” programmatically

后端 未结 8 1079
不思量自难忘°
不思量自难忘° 2020-12-24 03:02

I would like to be able to set \"Extend my Windows desktop onto this monitor\" via code. A PowerShell script would be ideal. WMI seems the way forward but I have zero knowle

8条回答
  •  情话喂你
    2020-12-24 03:21

    Here is my AutoIt-Script for switching monitors as my ATI graphics card doesn't allow me to have 3 monitors active at the same time. I have 2 monitors attached and a TV. This script is doing what VonC's script does but in a more effective and faster way.

    Run("C:\WINDOWS\system32\control.exe desk.cpl", "C:\Windows\system32\")
    WinWait("Screen Resolution")
    ControlCommand("Screen Resolution", "", "ComboBox1", "SetCurrentSelection", "SAMSUNG")
    
    if (ControlCommand("Screen Resolution", "", "ComboBox3", "GetCurrentSelection", "") = "Disconnect this display") Then
        ControlCommand("Screen Resolution", "", "ComboBox1", "SetCurrentSelection", "2")
        ControlCommand("Screen Resolution", "", "ComboBox3", "SetCurrentSelection", "3")
        ControlCommand("Screen Resolution", "", "ComboBox1", "SetCurrentSelection", "0")
        ControlCommand("Screen Resolution", "", "ComboBox3", "SetCurrentSelection", "1")
        ControlClick("Screen Resolution", "", "Button4")
        WinWait("Display Settings")
        ControlClick("Display Settings", "", "Button1")
    Else
        ControlCommand("Screen Resolution", "", "ComboBox3", "SetCurrentSelection", "3")
        ControlCommand("Screen Resolution", "", "ComboBox1", "SetCurrentSelection", "2")
        ControlCommand("Screen Resolution", "", "ComboBox3", "SetCurrentSelection", "1")
        ControlClick("Screen Resolution", "", "Button4")
        WinWait("Display Settings")
        ControlClick("Display Settings", "", "Button1")
    EndIf
    

    Just replace "SAMSUNG" with your third monitors/tvs name and you're all set! As you surely know you can convert it to an executable which runs on any machine even without AutoIt installed.

提交回复
热议问题