question

BoeDillard-9400 avatar image
0 Votes"
BoeDillard-9400 asked PC-6936 commented

Batch file or tool like powertoy to change the resolution or scale of windows with the press of 1 button?

I wrote a script but it requires logging on and off windows.

I have an enduser who gets agitated easily who doesn't want to go to screen settings and adjust the font and scaling - he has 2 settings he used depending on if he is working on his system or a remote system. He would like to switch from 100% to 125% scaling although he might consider a different resolution but his RD setting has to be 100% 1920x1080. When he uses that locally he finds it too small and hates wearing glasses.

There may be a better way of going about this than I'm suggesting. Thanks I was thinking 1 icon on his desktop that says 100% and one that says 125% but again perhaps there is a better way - FYI - he does not have admin rights.

He is running Windows 10 1909

windows-8
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
Just want to confirm the current situations.
Please feel free to let us know if you need further assistance.
If the reply is helpful, please "Accept Answer" to help other community members find it easier.

0 Votes 0 ·
IanXue-MSFT avatar image
2 Votes"
IanXue-MSFT answered PC-6936 commented

Hi,

The display scaling can be changed with SystemParametersInfo and SPI_SETLOGICALDPIOVERRIDE

https://social.msdn.microsoft.com/Forums/vstudio/en-US/3259c521-b3ed-4121-97da-70a08fb8bb19/change-setting?forum=windowsgeneraldevelopmentissues

The function can be called in a powershell script as follows (tested in Windows 10)

 # $scaling = 0 : 100% (default)
 # $scaling = 1 : 125% 
 # $scaling = 2 : 150% 
 # $scaling = 3 : 175% 
 param($scaling = 0)
 $source = @’
 [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
 public static extern bool SystemParametersInfo(
                  uint uiAction,
                  uint uiParam,
                  uint pvParam,
                  uint fWinIni);
 ‘@
 $apicall = Add-Type -MemberDefinition $source -Name WinAPICall -Namespace SystemParamInfo –PassThru
 $apicall::SystemParametersInfo(0x009F, $scaling, $null, 1) | Out-Null


You can create a shortcut to run the script. In the Target box in Shortcut tab it could be like this

 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\test\scale.ps1" 2

C:\test\scale.ps1 is path of the script and 2 is the value of the parameter $scaling

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Ian
Thank you for this brilliant script. Works like a charm. However, is it possible to have only one monitor apply those changes in a multi-display environment? Your script changes the settings on all screens at once.

0 Votes 0 ·

some how running this script as PS1 + value does not work, but when I save it into powershell profile
and use

$profile
dpiscale -1
dpiscale 0
dpiscale 1

works , can anyone explain to me why please?

0 Votes 0 ·
BoeDillard-9400 avatar image
0 Votes"
BoeDillard-9400 answered PC-6936 commented

Thanks so much. I tested on my system and I have admin rights. I manually opened powershell from windows and ran the second half after saving the first half. It runs but doesn't do anything - I tried with 0, 1, 2 and no change - I went to display settings to verify. Any guess what I'm doing wrong?


I also found this batch file that gets me close - if I could have 2 batch files - one to set it to 100% text size scaling and a different one for 150 I think I'd have what I need.

@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


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.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have changed the script and using value finally works

@ECHO OFF
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 WshShell.SendKeys "^{ESC}" >>"%TempVBSFile%"
ECHO Wscript.Sleep 500 >>"%TempVBSFile%"
ECHO WshShell.SendKeys "change the size of text, apps and other items" >>"%TempVBSFile%"
ECHO Wscript.Sleep 500 >>"%TempVBSFile%"
ECHO WshShell.SendKeys "{ENTER}" >>"%TempVBSFile%"
ECHO Wscript.Sleep 2000 >>"%TempVBSFile%"
ECHO WshShell.SendKeys "125" >>"%TempVBSFile%"
ECHO Wscript.Sleep 1000 >>"%TempVBSFile%"

ECHO WshShell.SendKeys "%%{F4}" >>"%TempVBSFile%"
CSCRIPT //nologo "%TempVBSFile%"
EXIT


the 125 value is for 125% , can change it to 100 , 150 and 200

However , using the powershell script is a lot more handy, and less waiting time

0 Votes 0 ·
IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered PC-6936 commented

Hi,

It appears a space is prepended to each line of the script when I use Code Sample of the forum and that makes the script not run. Try removing the spaces and see if the script works.

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

oh, that's why, thanks

0 Votes 0 ·
MikeTope-3828 avatar image
2 Votes"
MikeTope-3828 answered

Great little powershell script, but I don't agree the values.
0 means the recommended value, in my case 150%.
So I needed -2 for 100%, but it's a "uint", so it's got to be written as 4294967294.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.