Windows – Is it possible to change display scaling via command line

dpimultiple-monitorsscalingwindows 10

I've got a laptop with a 2560 x 1440 display, connected to 2 external 1080p monitors. The scaling is fine normally, with the native monitor at 125% and the 1080p monitors at 100%, but when I undock the laptop, sometimes the laptop goes to 200% scaling factor and I need to reset it manually in display settings.

I would like to find a command that emulates the setting here, such that I don't need to right click on the desktop and open display settings every time I unplug my external monitors:

enter image description here

The only registry keys/PowerShell commands I've found for this require logging out to take effect, which doesn't seem necessary given the GUI setting can take effect immediately.

Best Answer

Below is a batch script that will emulate the keyboard strokes to manipulate the GUI to adjust the Scale and layout options and Change the size or text, apps, and other items when it runs. This uses ms-settings:display to open the Display screen, and then it presses the tab key once and the up arrow 5 times using sendkeys to adjust the scale accordingly. It will press Alt+F4 at the end keys to close the screen once it completes. This method builds a dynamic vb script with a batch script and then executes the vb script with cscript to emulate pressing the keyboard keys.


Batch Script

Note: Just save this to a text file with a .bat or .cmd extension and execute it to run.

@ECHO OFF

explorer ms-settings:display
ping -n 2 127.0.0.1 > nul

:VBSDynamicBuild
SET TempVBSFile=%tmp%\~tmpSendKeysTemp.vbs
IF EXIST "%TempVBSFile%" DEL /F /Q "%TempVBSFile%"
ECHO Set WshShell = WScript.CreateObject("WScript.Shell") >>"%TempVBSFile%"
ECHO Wscript.Sleep 500                                    >>"%TempVBSFile%"
ECHO WshShell.SendKeys "{TAB}{UP 5}"                      >>"%TempVBSFile%"
ECHO Wscript.Sleep 500                                    >>"%TempVBSFile%"
ECHO WshShell.SendKeys "%%{F4}"                           >>"%TempVBSFile%"

CSCRIPT //nologo "%TempVBSFile%"
EXIT

Further Resources

Related Question