Running an executable, Screen Resolution for Multiple Monitors
Moderators: Dorian (MJT support), JRL
Running an executable, Screen Resolution for Multiple Monitors
A have a macro for managing / manipulating windows on PC with multiple monitors (similar to Display Fusion but with custom modes not supported by them). I have two 'issues' that I have work-arounds for, but I'm wondering if anyone has better alternatives.
1) I need a way to read the current screen resolution for the existing monitors. I did a fair amount of research but didn't find a workable alternative. My work-around was to send the output from the NirSoft MultiMonitorTool to a dataset and then read the data from there. This works, but it's slow. Does anyone have a better alternative? Much of what I found on the internet was old and I couldn't get it to work.
2) When I compile the script to share it with others I set up a windows 'hot-key' to run it. The issue is that using the hot-key causes the window that was active when the hot-key was pressed to lose focus. Adding commands to press 'Alt-Tab' to get back to the original window works - but is there a better way to do this?
1) I need a way to read the current screen resolution for the existing monitors. I did a fair amount of research but didn't find a workable alternative. My work-around was to send the output from the NirSoft MultiMonitorTool to a dataset and then read the data from there. This works, but it's slow. Does anyone have a better alternative? Much of what I found on the internet was old and I couldn't get it to work.
2) When I compile the script to share it with others I set up a windows 'hot-key' to run it. The issue is that using the hot-key causes the window that was active when the hot-key was pressed to lose focus. Adding commands to press 'Alt-Tab' to get back to the original window works - but is there a better way to do this?
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Running an executable, Screen Resolution for Multiple Monitors
I'm not too sure about question 1, but this might help with question 2.
The most basic answer is to use SetFocus at the beginning of the script.
The question is, do you know the name of the window? If not, then maybe we can figure that out.
You're correct in saying that the hot key causes the current window to lose focus. That of course means we can't use GetActiveWindow, as it's no longer active.
However, I noticed a while back that GetWindowList always seems to return a list in the order they were last active. I just tested this with Notepad1, Notepad2, Notepad3 etc. The last active window always seems to be the first one in the list.
So, would this work?
Or go through the entire list of open windows and SetFocus the one which matches the criteria
Or a combination of the two?
The most basic answer is to use SetFocus at the beginning of the script.
The question is, do you know the name of the window? If not, then maybe we can figure that out.
You're correct in saying that the hot key causes the current window to lose focus. That of course means we can't use GetActiveWindow, as it's no longer active.
However, I noticed a while back that GetWindowList always seems to return a list in the order they were last active. I just tested this with Notepad1, Notepad2, Notepad3 etc. The last active window always seems to be the first one in the list.
So, would this work?
Code: Select all
GetWindowList>winlist
Separate>winlist,CRLF,windows
SetFocus>windows_1
Code: Select all
//Loop through a list of windows
GetWindowList>winlist
Separate>winlist,CRLF,windows
Let>k=1
Repeat>k
Let>this=windows_%k%
//Does the Window title contain "Notepad"
Pos>Notepad,%this%,1,NotePos,
//if yes, do something
If>NotePos>0
Setfocus>%this%
Endif
Let>k=k+1
Until>k>windows_count
Yes, we have a Custom Scripting Service. Message me or go here
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Running an executable, Screen Resolution for Multiple Monitors
Regarding question 1, I had a Google around, and found this : https://www.windows-commandline.com/get ... nd-prompt/
Which may mean this could be a good starting point for you. Obviously you'd need to edit those output paths. Can be a temp directory if required.
Which may mean this could be a good starting point for you. Obviously you'd need to edit those output paths. Can be a temp directory if required.
Code: Select all
let>RP_WINDOWMODE=0
RunProgram>cmd /c wmic desktopmonitor get screenheight, screenwidth > d:\screen.txt
//or
RunProgram>cmd /c wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution > d:\screen.txt
Yes, we have a Custom Scripting Service. Message me or go here
Re: Running an executable, Screen Resolution for Multiple Monitors
. The issue with running the executable using a Windows Hot-Key is that I want to know which window was active when they pressed the Hot-Key and I won't be able to tell which window that was. Using commands to do an 'Alt-Tab' works but I'm not sure how reliable it is. Thank you for the suggestion to use GetWindowList. I will try it!
. Regarding getting the resolution for multiple monitors
. . GetScreenResolution works to return the resolution for the primary monitor but I need the current screen resolution for all connected monitors. I currently use my laptop monitor (1440x900) and one external monitor (1920x1080) but I will soon be adding two additional monitors which will likely be using yet another resoluton.
. . The wmic 'desktopmonitor' command did not return anything
. . The wmic 'win32_videocontroller' command returned a single width/height value of 2736/1824- which is the maximum supported resolution for my laptop monitor
. . From what I've read I think I need to collect the WmiMonitorID's and then from that, collect (or calculate) the current resolution for each monitor. I was unable to find a solution I could run directly within Macro Scheduler so I used my workaround with the NirSoft utility. I was hoping someone already had a solution. If not, I'll keep working on it in my 'spare' time
Thank you for the replies!
. Regarding getting the resolution for multiple monitors
. . GetScreenResolution works to return the resolution for the primary monitor but I need the current screen resolution for all connected monitors. I currently use my laptop monitor (1440x900) and one external monitor (1920x1080) but I will soon be adding two additional monitors which will likely be using yet another resoluton.
. . The wmic 'desktopmonitor' command did not return anything
. . The wmic 'win32_videocontroller' command returned a single width/height value of 2736/1824- which is the maximum supported resolution for my laptop monitor
. . From what I've read I think I need to collect the WmiMonitorID's and then from that, collect (or calculate) the current resolution for each monitor. I was unable to find a solution I could run directly within Macro Scheduler so I used my workaround with the NirSoft utility. I was hoping someone already had a solution. If not, I'll keep working on it in my 'spare' time
Thank you for the replies!
Re: Running an executable, Screen Resolution for Multiple Monitors
. The issue with running the executable using a Windows Hot-Key is that I want to know which window was active when they pressed the Hot-Key and I won't be able to tell which window that was. Using commands to do an 'Alt-Tab' works but I'm not sure how reliable it is. Thank you for the suggestion to use GetWindowList. I will try it!
. Regarding getting the resolution for multiple monitors
. . GetScreenResolution works to return the resolution for the primary monitor but I need the current screen resolution for all connected monitors. I currently use my laptop monitor (1440x900) and one external monitor (1920x1080) but I will soon be adding two additional monitors which will likely be using yet another resoluton.
. . The wmic 'desktopmonitor' command did not return anything
. . The wmic 'win32_videocontroller' command returned a single width/height value of 2736/1824- which is the maximum supported resolution for my laptop monitor
. . From what I've read I think I need to collect the WmiMonitorID's and then from that, collect (or calculate) the current resolution for each monitor. I was unable to find a solution I could run directly within Macro Scheduler so I used my workaround with the NirSoft utility. I was hoping someone already had a solution. If not, I'll keep working on it in my 'spare' time
Thank you for the replies!
. Regarding getting the resolution for multiple monitors
. . GetScreenResolution works to return the resolution for the primary monitor but I need the current screen resolution for all connected monitors. I currently use my laptop monitor (1440x900) and one external monitor (1920x1080) but I will soon be adding two additional monitors which will likely be using yet another resoluton.
. . The wmic 'desktopmonitor' command did not return anything
. . The wmic 'win32_videocontroller' command returned a single width/height value of 2736/1824- which is the maximum supported resolution for my laptop monitor
. . From what I've read I think I need to collect the WmiMonitorID's and then from that, collect (or calculate) the current resolution for each monitor. I was unable to find a solution I could run directly within Macro Scheduler so I used my workaround with the NirSoft utility. I was hoping someone already had a solution. If not, I'll keep working on it in my 'spare' time
Thank you for the replies!
Re: Running an executable, Screen Resolution for Multiple Monitors
The following PowerShell commands return the information I need but I'm having trouble getting them to work in Macro Scheduler:
/*
PS1:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Screen]::AllScreens | Clip.exe
*/
LabelToVar>PS1,PSCmd,1,1
Run>powershell.exe -%PSCmd%
wait>2
GetClipBoard>check_ps
**breakpoint**
This is the first time I've tried using PowerShell within Macro Scheduler. I'm obviously doing something wrong. Help?
/*
PS1:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Screen]::AllScreens | Clip.exe
*/
LabelToVar>PS1,PSCmd,1,1
Run>powershell.exe -%PSCmd%
wait>2
GetClipBoard>check_ps
**breakpoint**
This is the first time I've tried using PowerShell within Macro Scheduler. I'm obviously doing something wrong. Help?
Re: Running an executable, Screen Resolution for Multiple Monitors
Corrected syntax -now it works as expected:
Let>RP_WINDOWMODE=0
/*
PS1:
Add-Type -AssemblyName System.Windows.Forms;
[System.Windows.Forms.Screen]::AllScreens | Clip.exe;
*/
LabelToVar>PS1,PSCmd
Run>powershell.exe -command "%PSCmd%"
wait>10
GetClipBoard>check_ps
**breakpoint**
Let>RP_WINDOWMODE=0
/*
PS1:
Add-Type -AssemblyName System.Windows.Forms;
[System.Windows.Forms.Screen]::AllScreens | Clip.exe;
*/
LabelToVar>PS1,PSCmd
Run>powershell.exe -command "%PSCmd%"
wait>10
GetClipBoard>check_ps
**breakpoint**
Re: Running an executable, Screen Resolution for Multiple Monitors
Well done jbas!
I watched this thread with interest not commenting because I don't like the solutions I've used for multiple monitor resolution acquisition. This powershell solution is spectacular!
I did make a small alteration for timing. I removed your Wait>10 and added an RP_Wait>1 to cause Macro Scheduler to wait for the powershell script to finish before moving on to the other lines of code. And added WaitClipBoard> so the script could continue immediately after the clipboard stops changing. Seems to be working reliably but your results may vary. I'd suggest a very short wait ahead of WaitClipboard if the script ever fails to produce a result.
I watched this thread with interest not commenting because I don't like the solutions I've used for multiple monitor resolution acquisition. This powershell solution is spectacular!
I did make a small alteration for timing. I removed your Wait>10 and added an RP_Wait>1 to cause Macro Scheduler to wait for the powershell script to finish before moving on to the other lines of code. And added WaitClipBoard> so the script could continue immediately after the clipboard stops changing. Seems to be working reliably but your results may vary. I'd suggest a very short wait ahead of WaitClipboard if the script ever fails to produce a result.
Code: Select all
Let>RP_WINDOWMODE=0
Let>RP_Wait=1
/*
PS1:
Add-Type -AssemblyName System.Windows.Forms;
[System.Windows.Forms.Screen]::AllScreens | Clip.exe;
*/
LabelToVar>PS1,PSCmd
Run>powershell.exe -command "%PSCmd%"
WaitClipBoard
GetClipBoard>check_ps
MDL>check_ps
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Running an executable, Screen Resolution for Multiple Monitors
Hi JRL.
Thank you for that input. Most appreciated. I have a question, as someone who knows nothing about Powershell.
Right now I am using a 4k laptop connected with a USB Type-C > HDMI adapter to a 49 inch 4k TV as a secondary monitor. Are the results you see below what you'd expect from that setup? Maybe there's something screwy in my setup.
BitsPerPixel : 32
Bounds : {X=0,Y=0,Width=1536,Height=864}
DeviceName : \\.\DISPLAY1
Primary : True
WorkingArea : {X=0,Y=0,Width=1536,Height=824}
BitsPerPixel : 32
Bounds : {X=0,Y=-864,Width=1280,Height=720}
DeviceName : \\.\DISPLAY2
Primary : False
WorkingArea : {X=0,Y=-864,Width=1280,Height=680}
Thank you for that input. Most appreciated. I have a question, as someone who knows nothing about Powershell.
Right now I am using a 4k laptop connected with a USB Type-C > HDMI adapter to a 49 inch 4k TV as a secondary monitor. Are the results you see below what you'd expect from that setup? Maybe there's something screwy in my setup.
BitsPerPixel : 32
Bounds : {X=0,Y=0,Width=1536,Height=864}
DeviceName : \\.\DISPLAY1
Primary : True
WorkingArea : {X=0,Y=0,Width=1536,Height=824}
BitsPerPixel : 32
Bounds : {X=0,Y=-864,Width=1280,Height=720}
DeviceName : \\.\DISPLAY2
Primary : False
WorkingArea : {X=0,Y=-864,Width=1280,Height=680}
Yes, we have a Custom Scripting Service. Message me or go here
Re: Running an executable, Screen Resolution for Multiple Monitors
Hello Dorian,
Assuming you have a windows 10 computer, what do you see if you right click the desktop and select "Display Settings" from the menu? You should see representations of both monitors (1 and 2) and if you scroll down you will find what Windows reports as the resolution of the selected monitor.
If the Display Settings match the PS output, I'd suspect the monitor goes to 4k when an application asks for it and returns to more "reasonable" resolution otherwise. Seems your desktop icons would be dots at 4k resolution.
Google returned this PC World article.
Assuming you have a windows 10 computer, what do you see if you right click the desktop and select "Display Settings" from the menu? You should see representations of both monitors (1 and 2) and if you scroll down you will find what Windows reports as the resolution of the selected monitor.
If the Display Settings match the PS output, I'd suspect the monitor goes to 4k when an application asks for it and returns to more "reasonable" resolution otherwise. Seems your desktop icons would be dots at 4k resolution.
Google returned this PC World article.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Running an executable, Screen Resolution for Multiple Monitors
Both say 3840x2160, which is what I was expecting the PS output to be.
I think you've helped me figure it out. It's the zoom level.
Monitor 2
3840 x 2160 is scaled at 300%
1280 x 720 is 3840 x 2160 / 3
Monitor 1
3840 x 2160 is scaled at 250%
1536 x 824 is 3840 x 2160 / 2.5
Even though 2.5 x 824 is 2060, I think this must be the answer.
I think you've helped me figure it out. It's the zoom level.
Monitor 2
3840 x 2160 is scaled at 300%
1280 x 720 is 3840 x 2160 / 3
Monitor 1
3840 x 2160 is scaled at 250%
1536 x 824 is 3840 x 2160 / 2.5
Even though 2.5 x 824 is 2060, I think this must be the answer.
Yes, we have a Custom Scripting Service. Message me or go here
Re: Running an executable, Screen Resolution for Multiple Monitors
Happy to have pretended to help
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Running an executable, Screen Resolution for Multiple Monitors
Sometimes all it takes is bouncing off someone else, eh?
Yes, we have a Custom Scripting Service. Message me or go here