Setting display resolution and DPI scaling via Command Line - Windows

 #Windows


This is mainly useful for laptop users who connect to an external display at home and keep their laptop off to the side, farther back than when using it on the go.

Windows remembers screen position and orientation when displays are disconnected and reconnected, but it doesn’t adjust the built-in laptop display’s scaling. This means you have to manually change the scaling in display settings each time.

Strangely, Windows doesn’t provide a built-in command-line method to adjust display scaling. I tried modifying the registry directly, but while I could set the scaling value, I couldn’t get Windows to refresh the display for the change to take effect.

Then I found NirCmd, which can reset the display but not change scaling. So, I combined both methods—registry edits and a display reset—to make it work.

RegEdit
RegEdit

You will need to find the monitor ID in your registry - open (win+r) regedit.exe and navigate to HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\ - in my case it is LEN81980_00_07E2_93^D67EB3619EDA5B5DF73E8171F6077798

Windows display settings lists the recommended scaling
Windows display settings lists the recommended scaling

You'll need to first find your displays recommended scaling, or zero index, which is determined by Windows - it is NOT 100%!. For higher DPI displays, this will usually be 200%. You'll see in the script below dword 0xfffffffc which represents -4 - 200% less levels of 25% (175% > 150% > 125% > 100%), resulting in 100%.

Below are two .bat scripts to set scaling to 100% and 200%. You can modify them for other scaling levels.

@echo off
cd /d %~dp0
reg add "HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\LEN81980_00_07E2_93^D67EB3619EDA5B5DF73E8171F6077798" /v DpiValue /t REG_DWORD /d 0xfffffffc /f
nircmd setprimarydisplay 1

Here, it sets the dword to 0x00000000 - this is the displays default scaling,

@echo off
cd /d %~dp0
reg add "HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\LEN81980_00_07E2_93^D67EB3619EDA5B5DF73E8171F6077798" /v DpiValue /t REG_DWORD /d 0x00000000 /f
nircmd setprimarydisplay 1

On higher res displays, this will result in the display scaling being set to 100%.

And, for completeness, here is 225% (+1):

@echo off
cd /d %~dp0
reg add "HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\LEN81980_00_07E2_93^D67EB3619EDA5B5DF73E8171F6077798" /v DpiValue /t REG_DWORD /d 0x00000001 /f
nircmd setprimarydisplay 1

Hopefully you can work it out and make use. You'll need to save the above scripts as .bat files and you may have problems downloading them directly here, so I recommend you copy and paste to a file locally.

You can get NirCmd here: https://www.nirsoft.net/utils/nircmd.html