MScholtes / PSVirtualDesktop

VirtualDesktop is a Powershell module that provides commandlets to manage virtual desktops of Windows 10.
MIT License
303 stars 18 forks source link

Error moving window (Teams App) #46

Closed jcmarinn closed 1 month ago

jcmarinn commented 2 months ago

I'm trying to move the Microsoft Teams App window to one of my desktops with this command:

Get-desktop 3 | Move-Window (Find-WindowHandle "Microsoft Teams") | Switch-Desktop

This works OK for other apps like Outlook, but I get the following error when I try with Microsoft Teams:

MethodInvocationException: D:\OneDrive\Documents\PowerShell\Modules\VirtualDesktop\1.5.8\VirtualDesktop.ps1:2471 Line | 2471 | $Hwnd.MoveWindow([IntPtr]$Desktop) | ~~~~~~~~~~ | Exception calling "MoveWindow" with "1" argument(s): "Element not found. (0x8002802B (TYPE_E_ELEMENTNOTFOUND))"

Find-WindowHandle "Microsoft Teams" does return a handle correctly --> name of window changes depending on whats showing in TEAMS but it always ends with "Microsoft Teams" so Find-WindowHandle returns same handle every time.

MScholtes commented 2 months ago

Hello @jcmarinn,

I do not have Teams installed but as far as I know Teams does start several processes with each of it having potentially several windows so it would be luck if you obtain the handle of the correct window to move.

When I remember well the "classic" Teams starts more than one instance of teams.exe, you can check this with

Get-Process "teams"

Maybe you have luck when determing the handle of the main window with:

(Get-Process "teams")[0].MainWindowHandle

( [0] is here for the first found instance of teams.exe )

Sorry I cannot help more, but some programs - first of all browsers like Edge or Chrome) are designed this way.

Greetings

Markus

MScholtes commented 1 month ago

I assume that the issue no longer exists as there is no feedback.