Reputation: 477
I wannt to move a window between desktops. Something like this:
$app = Start-Process notepad.exe -PassThru
sleep 1
$hndl = $app.MainWindowHandle
# Move notepad window to desktop №2
[DesktopManager]::MoveToDesktop($hndl, 2) # True
# Get the number of desktop, where the app is located now
[DesktopManager]::GetDesktopWindow($hndl) # 2
#etc...
I have found this and this, but I don't understand how to run it via PowerShell.
Also i have found this...
Upvotes: 1
Views: 1477
Reputation: 997
It looks like the thing you ask about was intentionally not allowed by Windows APIs. I see that the pages you linked to use the IVirtualDesktopManager interface but it is not intended to move foreign windows.
Raymond Chen's article Virtual desktops are an end-user window management feature, not a programmatic one about the IVirtualDesktopManager interface says "the only thing you can do is make one window join another window’s virtual desktop... [the interface] is not a general purpose interface for moving windows onto arbitrary virtual desktops."
Also, here (the post is in Russian; the translation is mine) it is said that: "MoveWindowToDesktop works only for windows launched by the process, i.e. it is not possible to move a foreign window with this function."
Upvotes: 2