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

Boe Dillard 666 Reputation points
2020-12-14T17:44:04.26+00:00

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
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,639 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 28,976 Reputation points Microsoft Vendor
    2020-12-15T09:56:26.76+00:00

    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.

    5 people found this answer helpful.

  2. Mike Tope 16 Reputation points
    2021-04-09T10:59:27.583+00:00

    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.

    3 people found this answer helpful.

  3. Ian Xue (Shanghai Wicresoft Co., Ltd.) 28,976 Reputation points Microsoft Vendor
    2020-12-15T15:04:39.993+00:00

    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 person found this answer helpful.

  4. Boe Dillard 666 Reputation points
    2020-12-15T13:39:57.197+00:00

    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.