2

I found this batch file and it gets me close Is it possible to change display scaling via command line?_ . I'd like 1 batch file that gets me to 150% without any more clicking than a batch file called 150.bat and 1 batch file called 100.bat that gets me to 100% without any more input. Is it possible?

I could call this 100.bat

@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 2}{UP 1}" >>"%TempVBSFile%" ECHO Wscript.Sleep 500 >>"%TempVBSFile%" ECHO WshShell.SendKeys "%%{F4}" >>"%TempVBSFile%" CSCRIPT //nologo "%TempVBSFile%"

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

CSCRIPT //nologo "%TempVBSFile%" EXIT

And this 125.bat

@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 2}{DOWN 1}" >>"%TempVBSFile%" ECHO Wscript.Sleep 500 >>"%TempVBSFile%" ECHO WshShell.SendKeys "%%{F4}" >>"%TempVBSFile%" CSCRIPT //nologo "%TempVBSFile%"

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

CSCRIPT //nologo "%TempVBSFile%" EXIT

However if they click one too many times they can go too far - I'd like it if I could set a specific number instead of moving up and down.

Giacomo1968
  • 58,727

1 Answers1

2

1. Before using sendkeys, bring the interface that you will "interact" to the foreground and then try to send inputs:

ECHO;WScript.Sleep 500 : objShell.AppActivate "Settings"

2. If you need to send TAB multiple times "{TAB 2}{UP 1}" , use:

ECHO WshShell.SendKeys "{TAB}{TAB}{UP}"

3. You need more one %% escaping in:

ECHO WshShell.SendKeys "%%{F4}"

ECHO WshShell.SendKeys "%%%{F4}"

4. Whatever value (in UPs/DOWn) is already defined in the interface, you need to reset (bring it to the 1st position in the dropdown menu), and then set the item below in the listing x times necessary until you reach the desired listed value position:

echo;objShell.SendKeys "{TAB}{TAB}{~}{UP}{UP}{UP}{UP}"
echo;objShell.SendKeys "{UP}{UP}{UP}{DOWN}{~}"

:: it seems like a paranoid way of doing it, but it works...



  • To change display scaling to 100:
@echo off & setlocal

mode con: cols=50 Lines=02 2>nul del/q /f %tmp%_tmp_send_keys_.vbs" set "tmp_send_keys=%tmp%_tmp_send_keys_.vbs" explorer ms-settings:display && ping -n 2 127.1 >nul

:vbs_dynamic_build_100 2>nul del/q /f "%tmp_send_keys%" & >"%tmp_send_keys%" ^ ( echo;Set objShell=WScript.CreateObject("WScript.Shell"^) echo;WScript.Sleep 500 : objShell.AppActivate "Settings" echo;objShell.SendKeys "{TAB}{TAB}{~}{UP}{UP}{UP}{UP}" echo;objShell.SendKeys "{UP}{UP}{UP}{~}%%%{F4}" ) && cscript //nologo "%tmp_send_keys%"

>nul 2>&1 ( explorer ms-settings:display & ping -n 4 -4 127.1 %APPDIRR__%taskkill/FI "WindowTitle eq Settings*" del/q /f "%_tmp_send_keys%" & endlocal & goto :EOF)


  • To change display scaling to 125:
@echo off & setlocal

mode con: cols=50 Lines=02 2>nul del/q /f %tmp%_tmp_send_keys_.vbs" set "tmp_send_keys=%tmp%_tmp_send_keys_.vbs" explorer ms-settings:display && ping -n 2 127.1 >nul

:vbs_dynamic_build_125 2>nul del/q /f "%tmp_send_keys%" & >"%tmp_send_keys%" ^ ( echo;Set objShell=WScript.CreateObject("WScript.Shell"^) echo;WScript.Sleep 500 : objShell.AppActivate "Settings" echo;objShell.SendKeys "{TAB}{TAB}{~}{UP}{UP}{UP}{UP}" echo;objShell.SendKeys "{UP}{UP}{UP}{DOWN}{~}" echo;objShell.SendKeys "%%%{F4}" ) && cscript //nologo "%tmp_send_keys%"

>nul 2>&1 ( explorer ms-settings:display & ping -n 4 -4 127.1 %APPDIRR__%taskkill/FI "WindowTitle eq Settings*" del/q /f "%_tmp_send_keys%" & endlocal & goto :EOF)


  • To change display scaling to 150:
@echo off & setlocal

mode con: cols=50 Lines=02 2>nul del/q /f %tmp%_tmp_send_keys_.vbs" set "tmp_send_keys=%tmp%_tmp_send_keys_.vbs" explorer ms-settings:display && ping -n 2 127.1 >nul

:vbs_dynamic_build_150 >"%tmp_send_keys%" ( echo;Set objShell=WScript.CreateObject("WScript.Shell"^) echo;WScript.Sleep 500 : objShell.AppActivate "Settings" echo;objShell.SendKeys "{TAB}{TAB}{~}{UP}{UP}{UP}{UP}" echo;objShell.SendKeys "{UP}{UP}{UP}{DOWN}{DOWN}" echo;objShell.SendKeys "{~}%%%{F4}" ) && cscript //nologo "%tmp_send_keys%"

>nul 2>&1 ( explorer ms-settings:display & ping -n 4 -4 127.1 %APPDIRR__%taskkill/FI "WindowTitle eq Settings*" del/q /f "%_tmp_send_keys%" & endlocal & goto :EOF)


  • Some further reading:

[√] SendKeys Method in VBScript

[√] *WshShell.SendKeys "Character_string_and/or_SendKeys"

Io-oI
  • 9,237