windowspowershellwindows-10powershell-5.0virtual-desktop

Starting programs on multiple desktops using powershell in windows 10


Suppose I want to start several programs C:\program1.exe, C:\program2.exe, etc. on multiple desktops in windows 10. For example, programs 1 and 2 should be started on desktop 1 side-by-side, program 3 should be started on the second desktop, while program 4 should be started minimized on the third desktop.

This should be achieved using either a powershell or batch script. The solution would be perfect if the powershell script automatically detects whether enough desktops are open and open more desktops if necessary.

batch-file-run-program-set position provides a solution to the problem of opening multiple programs side by side and resizing them. However, these solutions do not address multiple windows 10 desktops. The solutions rely on Monitorinfoview and NirCmd (same website). The tool Monitorinfoview does not retrieve multiple desktop information, but only multiple screens. NirCmd also does not include commands to send programs to specific desktops.


Solution

  • There are Powershell commands that work with virtual desktops. First, you will have to install virtual desktop module with Install-Module VirtualDesktop

    # Switch to desktop 2 (count starts with 0)
    Get-Desktop 1 | Switch-Desktop
        
    # Move obs64.exe to desktop 3
    (ps obs64)[0].MainWindowHandle | Move-Window (Get-Desktop 2) | Out-Null
    

    You may have to wait for the starting process to initialize its window with Start-Sleep

    Read more here: https://gallery.technet.microsoft.com/scriptcenter/Powershell-commands-to-d0e79cc5