PoweShell Script to open specific app in secondary monitor

Dharmesh Kulkarni 1 Reputation point
2021-12-03T12:50:29.887+00:00

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

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,600 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Jose Antonio Silva 11 Reputation points
    2021-12-03T22:41:50.793+00:00

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

    0 comments No comments

  2. Limitless Technology 39,781 Reputation points
    2021-12-06T09:42:07.817+00:00

    Hello,

    Launch the application:

    Use FindWindowA function (winuser.h)
    https://zcusa.951200.xyz/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://zcusa.951200.xyz/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://zcusa.951200.xyz/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://zcusa.951200.xyz/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--

    0 comments No comments

  3. Stefan K 101 Reputation points
    2025-01-10T09:32:59.8433333+00:00

    a little late but for anyone who is finding this thread check this PS Module:
    https://github.com/MScholtes/PSVirtualDesktop


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.