question

DharmeshKulkarni-8312 avatar image
0 Votes"
DharmeshKulkarni-8312 asked joseantoniosilva answered

PoweShell Script to open specific app in secondary monitor

can anyone tell me what is the powershell script to open specific app in secondary monitor

windows-server-powershell
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.

joseantoniosilva avatar image
0 Votes"
joseantoniosilva answered

You can automate that using AutoIT cmdlets. check these examples:
https://www.autoitconsulting.com/site/scripting/autoit-cmdlets-for-windows-powershell/

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.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello,

Launch the application:

Use FindWindowA function (winuser.h)
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowa?redirectedfrom=MSDN to retrieve the handle to the window. If the window doesn’t exist yet, the process hasn’t created it yet; sleep for 500ms and then try again.

Use SetWindowPos function (winuser.h)

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos?redirectedfrom=MSDN to change the position of the window.

If you don’t know the title of the window, you can’t use FindWindow. In that case,

Launch the application and get the process handle by retrieving Process.Handle.

Use EnumWindows EnumWindows function (winuser.h)
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos?redirectedfrom=MSDN to retrieve all the windows. For each window, use GetWindowThreadProcessId to check whether it belongs to your process. If no window belongs to your process, wait and keep trying.

Use SetWindowPos function (winuser.h)
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos?redirectedfrom=MSDN to change the position of the window.

Of course, you can use Screen.AllScreens[n].WorkingArea to retrieve the position and size of the screen you want, and then you can position the window relative to that.



--If the reply is helpful, please Upvote and Accept as answer--

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.