Here is a Windows 10 64-bit visual basic script and Powershell 5 script.
ScreenCapture of the VBscript in action. (1.1MB mp4)
Windows 10 64-bit visual basic script using SendKeys to change display scale and resolution, open app, and restore scale and resolution when app closes. No restart required.
Copy and paste the code into a new text document. Save it as a .vbs file (i.e. ChangeDisplay.vbs), edit it, and run it.
Changing the scaling and resolution will mess up your desktop icon layout. Download, install, and learn how to use a command line desktop icon layout backup like:
DesktopOK v4.24. Save and restore desktop icon layout from the command line. Put DesktopCmd64.exe somewhere in your PATH, add it to your PATH, or just put it in your windows folder.
and
DesktopRestore v1.6.3.031. Save and restore desktop icon layout from the command line. 64-bit command line version fails occasionally in Windows 10 64-bit? Put DesktopRestore64.exe somewhere in your PATH, add it to your PATH, or just put it in your windows folder.
Edit the script:
Change "PUT THE IMAGENAME OF YOUR APP HERE", "CHANGE THE FOLLOWING {UP} / {DOWN}?", and CHANGE THE COMMAND THAT STARTS YOUR APP.
Open the display settings window explorer ms-settings:display and figure out what combination of TAB and UP or DOWN keystrokes you need to get the setting you want and "CHANGE THE FOLLOWING {UP} / {DOWN}?"
If you open the display settings window another way your number of TAB/S might be different.
The Wscript.Sleep timing can be tricky. Both decreasing the sleep and increasing the sleep can break the script. Running the script during times of high disk use can cause the script to fail. There are a lot of different things you can try:
- focus at stackoverflow
- pause at stackoverflow
- Google search - windows 10 wscript wait for process to finish loading
but I am sticking with Wscript.Sleep alone because it is working for me. See comments around Wscript.Sleep 2000
.
BEGIN MOSTLY NATIVE USING A VISUAL BASIC SCRIPT
' WINDOWS 10 64-BIT VISUAL BASIC SCRIPT TO CHANGE DISPLAY SCALE AND RESOLUTION, OPEN APP, AND RESTORE SCALE AND RESOLUTION WHEN APP CLOSES.
' https://superuser.com/questions/1489592/windows-10-batch-script-to-change-display-settings-for-specific-application
' All native except DesktopOK and DesktopRestore. Does not require restart.
' Changing the scaling and resolution will mess up your desktop icon layout. Download, install, and learn how to use a command line desktop icon layout backup like:
' DesktopOK v4.24. Save and restore desktop icon layout from the command line. https://www.softwareok.com/?Download=DesktopOK
' Put DesktopCmd64.exe somewhere in your PATH.
' and
' DesktopRestore v1.6.3.031. Save and restore desktop icon layout from the command line. 64-bit command line version fails occasionally in Windows 10 64-bit? http://www.midiox.com/desktoprestore.htm
' Put DesktopRestore64.exe somewhere in your PATH.
' Change "PUT THE IMAGENAME OF YOUR APP HERE", "CHANGE THE FOLLOWING {UP} / {DOWN}?", AND CHANGE THE COMMAND THAT STARTS YOUR APP.
' Open the display settings window (explorer ms-settings:display) and figure out what combination of TAB AND UP OR DOWN keystrokes you need to get the setting you want and "CHANGE THE FOLLOWING {UP} / {DOWN}?"
' If you open the display settings window another way your number of TAB/S might be different.
' BEGIN CHANGE TO 1920 X 1080 W/ 100% SCALING
option explicit
DIM strComputer,WshShell,HostName,Ping,FileName,Return
SET WshShell = WScript.CreateObject("WScript.Shell")
' BEGIN BACKUP DESKTOP ICON LAYOUT
FileName = "%USERPROFILE%\Desktop\DesktopIconLayout" & timer & ".dok"
WshShell.Run "desktoprestore64.exe /save /silent " & FileName, 0, False
FileName = "%USERPROFILE%\Desktop\DesktopIconLayout" & timer & ".dtr"
WshShell.Run "DesktopCmd64.exe save /f " & FileName, 0, False
' END BACKUP DESKTOP ICON LAYOUT
' BEGIN KILL APP
' PUT THE IMAGENAME OF YOUR APP HERE
' I.E. replace iexplore.exe
FileName = "iexplore.exe"
WshShell.Run "taskkill /im " & FileName & " /f", 0, False
' END KILL APP
' BEGIN CLOSE AND OPEN DISPLAY SETTINGS WINDOW
strComputer = "." ' local computer
FileName = "SystemSettings.exe"
if isProcessRunning(strComputer,FileName) then
WshShell.Run "taskkill /im " & FileName & " /f", 0, False
WshShell.Run "explorer ms-settings:display"
else
WshShell.Run "explorer ms-settings:display"
end if
Set strComputer = Nothing
Set FileName = Nothing
' END CLOSE AND OPEN DISPLAY SETTINGS WINDOW
' You have to give the display settings window enough time to load.
' There are a lot of different things you can try.
' If I change the following Wscript.Sleep to 4 seconds and leave the later one at 2 seconds the script fails
' even though 2 seconds works.
Wscript.Sleep 2000
' BEGIN CHANGE SCALE
' CHANGE THE FOLLOWING {UP} / {DOWN}?
WshShell.SendKeys "{TAB 2}{DOWN}"
' END CHANGE SCALE
Wscript.Sleep 750
' BEGIN CHANGE RESOLUTION
' CHANGE THE FOLLOWING {UP} / {DOWN}?
WshShell.SendKeys "{TAB 2}{DOWN}"
' END CHANGE RESOLUTION
Wscript.Sleep 750
' BEGIN ACCEPT RESOLUTION CHANGE
WshShell.SendKeys "{TAB}"
Wscript.Sleep 750
WshShell.SendKeys "{ENTER}"
' END ACCEPT RESOLUTION CHANGE
Wscript.Sleep 750
' BEGIN Return TO THE "FIND A SETTING" BOX. IMPROVES RELIABILITY.
' BEGIN PROCEDURE CHANGES IF PC IS ON/OFFLINE
' Dim HostName
' HostName = "8.8.8.8"
' Ping = WshShell.Run("Ping -n 1 " & HostName, 0, True)
' Select Case Ping
' Case 0
' WshShell.SendKeys "{TAB}" ' Online
' Case 1
' WshShell.SendKeys "{TAB}" ' Offline
' End Select
' END PROCEDURE CHANGES IF PC IS ON/OFFLINE
WshShell.SendKeys "{TAB}"
' END Return TO THE "FIND A SETTING" BOX. IMPROVES RELIABILITY.
Wscript.Sleep 750
' CLOSE DISPLAY SETTINGS WINDOW
WshShell.SendKeys "%{F4}"
' END CHANGE TO 1920 X 1080 W/ 100% SCALING
' BEGIN OPEN APP. SCRIPT STOPS UNTIL APP CLOSED.
' CHANGE THE COMMAND THAT STARTS YOUR APP.
' Return = WshShell.Run("""C:\Program Files (x86)\Jasc Software Inc\Paint Shop Pro 7\psp.exe""", 1, true)
Return = WshShell.Run("iexplore.exe", 1, true)
' WScript.Echo "HI"
' END OPEN APP. SCRIPT STOPS UNTIL APP CLOSED.
' BEGIN CHANGE TO 3840 X 2160 W/ 300% SCALING
' BEGIN OPEN DISPLAY SETTINGS WINDOW
WshShell.Run "explorer ms-settings:display"
' END OPEN DISPLAY SETTINGS WINDOW
' You have to give the display settings window enough time to load.
Wscript.Sleep 2000
' BEGIN CHANGE SCALE
' CHANGE THE FOLLOWING {UP} / {DOWN}?
WshShell.SendKeys "{TAB 2}{UP}"
' END CHANGE SCALE
Wscript.Sleep 750
' BEGIN CHANGE RESOLUTION
' CHANGE THE FOLLOWING {UP} / {DOWN}?
WshShell.SendKeys "{TAB 2}{UP}"
Wscript.Sleep 750
' END CHANGE RESOLUTION
' BEGIN ACCEPT RESOLUTION CHANGE
WshShell.SendKeys "{TAB}"
Wscript.Sleep 750
WshShell.SendKeys "{ENTER}"
' END ACCEPT RESOLUTION CHANGE
Wscript.Sleep 750
' BEGIN Return TO THE "FIND A SETTING" BOX. IMPROVES RELIABILITY.
WshShell.SendKeys "{TAB}"
Wscript.Sleep 750
' END Return TO THE "FIND A SETTING" BOX. IMPROVES RELIABILITY.
' CLOSE DISPLAY SETTINGS WINDOW
WshShell.SendKeys "%{F4}"
' END CHANGE TO 3840 X 2160 W/ 300% SCALING
' EXIT THE SCRIPT
WScript.Quit
' Function to check if a process is running
function isProcessRunning(byval strComputer,byval FileNameName)
Dim objWMIService, strWMIQuery
strWMIQuery = "Select * from Win32_Process where name like '" & FileNameName & "'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
isProcessRunning = true
else
isProcessRunning = false
end if
end function
WITH MY COMMENTS ABOVE YOU COULD ALSO USE THIS POWERSHELL SCRIPT.
WINDOWS 10 64-bit powershell 5 script using sendkeys to change display scale and resolution, open app, and restore scale and resolution when app closes.
ScreenCapture of the powershell script in action (1.22MB mp4)
Create a shortcut to the script:
C:\Windows\System32\cmd.exe /c start /min "" C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -Command "& "%userprofile%\desktop\1.ps1""
or
C:\Windows\System32\cmd.exe /c start /min "" C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -ExecutionPolicy Bypass -Command "& "%userprofile%\desktop\1.ps1""
# WINDOWS 10 64-BIT POWERSHELL 5 SCRIPT USING SENDKEYS TO CHANGE DISPLAY SCALE AND RESOLUTION, OPEN APP, AND RESTORE SCALE AND RESOLUTION WHEN APP CLOSES.
# https://superuser.com/questions/1489592/windows-10-batch-script-to-change-display-settings-for-specific-application
# find process name with get-process
# if the app and / or settings windows are open the script will fail.
stop-process -name iexplore
stop-process -name systemsettings
# save the desktop icon layout
$a = (Get-Date).ToString('mmss')
start-process "$env:windir\DesktopRestore64.exe" "/save /silent $env:userprofile\Desktop\DesktopIconLayout$a.dok"
start-process "$env:windir\DesktopCmd64.exe" "save /f $env:userprofile\Desktop\DesktopIconLayout$a.dtr"
# the settings window
$WshShell = New-Object -com Wscript.Shell
explorer ms-settings:display
Start-Sleep -s 2
$WshShell.SendKeys("{TAB}"*2)
$WshShell.SendKeys("{DOWN}")
Start-Sleep -s 1
$WshShell.SendKeys("{TAB}"*2)
$WshShell.SendKeys("{DOWN}")
Start-Sleep -s .750
$WshShell.SendKeys("{TAB}{ENTER}{TAB}")
Start-Sleep -s .750
$WshShell.SendKeys("%{F4}")
# Start-Process can be tricky. Run "gci Env:" On my machine:
# $env:ProgramFiles = c:\program files (x86)
# $env:ProgramW6432 = c:\program files
# Start-Process "$env:ProgramFiles\Internet Explorer\iexplore.exe" -NoNewWindow -Wait
Start-Process "$env:ProgramW6432\Internet Explorer\iexplore.exe" -NoNewWindow -Wait
# the settings window
explorer ms-settings:display
Start-Sleep -s 2
$WshShell.SendKeys("{TAB}"*2)
$WshShell.SendKeys("{UP}")
Start-Sleep -s 2
$WshShell.SendKeys("{TAB}"*2)
$WshShell.SendKeys("{UP}")
Start-Sleep -s .750
$WshShell.SendKeys("{TAB}{ENTER}{TAB}")
Start-Sleep -s .750
$WshShell.SendKeys("%{F4}")
exit