Nine Posted May 25, 2022 Author Share Posted May 25, 2022 @ycomp Just out of curiosity, could you provide the full scite console ? After a quick search, I was not able to find the interface to Virtual Desktop on Win11. If someone can link me, I would take a look at it. Maybe there is only small changes ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ycomp Posted May 25, 2022 Share Posted May 25, 2022 ok, note i'm not running your full script the stuff between "please close all additional virtual desktops") and the __uuidof() function was removed to make it easier to test Quote >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3" /UserParams +>16:09:01 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_11/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\misha\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\misha\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.16.0) from:C:\Program Files (x86)\AutoIt3 input:D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3 +>16:09:02 AU3Check ended.rc:0 >Running:(3.3.16.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3" False--> SetHotKey Restart failed, Ctrl+BREAK to Stop. Immersive shell = 1 Service pointer = 2871787528440 Service = 1 View collection pointer = 2871787530232 View collection = 1 Virtual Desktop pointer = 0 Virtual Desktop = 0 Virtual Desktop Pinned Apps = 2871787542104 Virtual Desktop Pinned Apps = 1 "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3" (169) : ==> Variable must be of type "Object".: $iHresult = $oVirtualDesktopManagerInternal.GetCount($iCount) $iHresult = $oVirtualDesktopManagerInternal^ ERROR ->16:09:02 AutoIt3.exe ended.rc:1 +>16:09:03 AutoIt3Wrapper Finished. >Exit code: 1 Time: 2.69 Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2022 Author Share Posted May 25, 2022 Thanks. Clearly VirtualDesktopManagerInternal interface does not exist in the same form in Windows 11. I tend to believe it has simply been removed and replaced by something else. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2022 Author Share Posted May 25, 2022 @ycomp I may have found something. Could you try to replace that line from example 2 to : Local $CLSID_VirtualDesktopManagerInternal = "{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}" And run it again. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ycomp Posted May 25, 2022 Share Posted May 25, 2022 replaced it, same error I know they rewrote the taskbar in win11 to use some kind of special new UI framework microsoft has, no idea about virtual desktops. However, they really look and act the same so I doubt they changed that internally. The big difference is that you can move desktops around in win11.. drag them. I don't know if newer versions of win 10 can do this or not Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2022 Author Share Posted May 25, 2022 @ycomp I believe I made a mistake, it is the IID that needs to be changed not the CLSID : Local $IID_IVirtualDesktopManagerInternal = "{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}" “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ycomp Posted May 25, 2022 Share Posted May 25, 2022 replaced it, something is not right.. it doesn't give that error but doesn't make it to my hello consolewrite expandcollapse popup#include <Debug.au3> #include <Constants.au3> #include <GUIConstants.au3> ;_DebugSetup("LAzy Summer Home") ;_DebugOut("Right outside...") ;~ _DebugSetup("hi") ;~ _DebugOut("FAILED TAGGING") ;~ _DebugOut(" - Moved Folder") #include <Array.au3> ;~ Local $failedMoving[0][2] ;~ Dim $a = [["abc", "TAG-FAILED"]] ;~ _ArrayAdd($failedMoving, $a) ;~ _ArrayDisplay($failedMoving) ;~ While 1 ;~ Dim $text = InputBox("Text", "Enter some Text to Match") ;~ if @error <> 0 Then ExitLoop ;~ If StringRegExp($text, "(?i)(Garcia|JGB|Legion of Mary|Reconstruction|Old & in the Way|Old and in the way)") Then ;~ MsgBox(0, "MATCHED", "matched Jerry!") ;~ Else ;~ MsgBox(0, "NO MATCH", "poor Jerry..") ;~ EndIf ;~ WEnd ;~_ArrayDisplay($CmdLine) Opt("MustDeclareVars", True) ;If @OSVersion <> "WIN_10" Then Exit MsgBox($MB_SYSTEMMODAL, "", "This script only runs on Win 10") ; Instanciation objects Local $CLSID_ImmersiveShell = "{c2f03a33-21f5-47fa-b4bb-156362a2f239}" Local $IID_IUnknown = "{00000000-0000-0000-c000-000000000046}" Local $IID_IServiceProvider = "{6D5140C1-7436-11CE-8034-00AA006009FA}" Local $tIID_IServiceProvider = __uuidof($IID_IServiceProvider) Local $tagIServiceProvider = _ "QueryService hresult(struct*;struct*;ptr*);" ; VirtualDesktopManagerInternal object Const Enum $eLeftDirection = 3, $eRightDirection Local $CLSID_VirtualDesktopManagerInternal = "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}" Local $tCLSID_VirtualDesktopManagerInternal = __uuidof($CLSID_VirtualDesktopManagerInternal) Local $IID_IVirtualDesktopManagerInternal = "{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}" Local $tIID_IVirtualDesktopManagerInternal = __uuidof($IID_IVirtualDesktopManagerInternal) Local $tagIVirtualDesktopManagerInternal = _ "GetCount hresult(int*);" & _ "MoveViewToDesktop hresult(ptr;ptr);" & _ "CanViewMoveDesktops hresult(ptr;bool*);" & _ "GetCurrentDesktop hresult(ptr*);" & _ "GetDesktops hresult(ptr*);" & _ "GetAdjacentDesktop hresult(ptr;int;ptr*);" & _ "SwitchDesktop hresult(ptr);" & _ "CreateDesktopW hresult(int*);" & _ "RemoveDesktop hresult(ptr;ptr);" & _ "FindDesktop hresult(struct*;ptr*);" ; ApplicationViewCollection object Local $CLSID_IApplicationViewCollection = "{1841C6D7-4F9D-42C0-AF41-8747538F10E5}" Local $tCLSID_IApplicationViewCollection = __uuidof($CLSID_IApplicationViewCollection) Local $IID_IApplicationViewCollection = "{1841C6D7-4F9D-42C0-AF41-8747538F10E5}" Local $tIID_IApplicationViewCollection = __uuidof($IID_IApplicationViewCollection) Local $tagIApplicationViewCollection = _ "GetViews hresult(struct*);" & _ "GetViewsByZOrder hresult(struct*);" & _ "GetViewsByAppUserModelId hresult(wstr;struct*);" & _ "GetViewForHwnd hresult(hwnd;ptr*);" & _ "GetViewForApplication hresult(ptr;ptr*);" & _ "GetViewForAppUserModelId hresult(wstr;int*);" & _ "GetViewInFocus hresult(ptr*);" ; ApplicationView object Local $IID_IApplicationView = "{372E1D3B-38D3-42E4-A15B-8AB2B178F513}" Local $tagIApplicationView = _ "GetIids hresult(ulong*;ptr*);" & _ "GetRuntimeClassName hresult(str*);" & _ "GetTrustLevel hresult(int*);" & _ "SetFocus hresult();" & _ "SwitchTo hresult();" & _ "TryInvokeBack hresult(ptr);" & _ "GetThumbnailWindow hresult(hwnd*);" & _ "GetMonitor hresult(ptr*);" & _ "GetVisibility hresult(int*);" & _ "SetCloak hresult(int;int);" & _ "GetPosition hresult(clsid;ptr*);" & _ "SetPosition hresult(ptr);" & _ "InsertAfterWindow hresult(hwnd);" & _ "GetExtendedFramePosition hresult(struct*);" & _ "GetAppUserModelId hresult(wstr*);" & _ "SetAppUserModelId hresult(wstr);" & _ "IsEqualByAppUserModelId hresult(wstr;int*);" & _ "GetViewState hresult(uint*);" & _ "SetViewState hresult(uint);" & _ "GetNeediness hresult(int*);" ; VirtualDesktopPinnedApps object Local $CLSID_VirtualDesktopPinnedApps = "{b5a399e7-1c87-46b8-88e9-fc5747b171bd}" Local $tCLSID_VirtualDesktopPinnedApps = __uuidof($CLSID_VirtualDesktopPinnedApps) Local $IID_IVirtualDesktopPinnedApps = "{4ce81583-1e4c-4632-a621-07a53543148f}" Local $tIID_IVirtualDesktopPinnedApps = __uuidof($IID_IVirtualDesktopPinnedApps) Local $tagIVirtualDesktopPinnedApps = _ "IsAppIdPinned hresult(wstr;bool*);" & _ "PinAppID hresult(wstr);" & _ "UnpinAppID hresult(wstr);" & _ "IsViewPinned hresult(ptr;bool*);" & _ "PinView hresult(ptr);" & _ "UnpinView hresult(ptr);" ; Miscellaneous objects Local $IID_IObjectArray = "{92ca9dcd-5622-4bba-a805-5e9f541bd8c9}" Local $tagIObjectArray = _ "GetCount hresult(int*);" & _ "GetAt hresult(int;ptr;ptr*);" Local $IID_IVirtualDesktop = "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}" Local $tIID_IVirtualDesktop = __uuidof($IID_IVirtualDesktop) Local $tagIVirtualDesktop = _ "IsViewVisible hresult(ptr;bool*);" & _ "GetId hresult(clsid*);" ; objects creation Local $pService Local $oImmersiveShell = ObjCreateInterface($CLSID_ImmersiveShell, $IID_IUnknown, "") ConsoleWrite("Immersive shell = " & IsObj($oImmersiveShell) & @CRLF) $oImmersiveShell.QueryInterface($tIID_IServiceProvider, $pService) ConsoleWrite("Service pointer = " & $pService & @CRLF) Local $oService = ObjCreateInterface($pService, $IID_IServiceProvider, $tagIServiceProvider) ConsoleWrite("Service = " & IsObj($oService) & @CRLF) Local $pApplicationViewCollection, $pVirtualDesktopManagerInternal, $pVirtualDesktopPinnedApps $oService.QueryService($tCLSID_IApplicationViewCollection, $tIID_IApplicationViewCollection, $pApplicationViewCollection) ConsoleWrite("View collection pointer = " & $pApplicationViewCollection & @CRLF) Local $oApplicationViewCollection = ObjCreateInterface($pApplicationViewCollection, $IID_IApplicationViewCollection, $tagIApplicationViewCollection) ConsoleWrite("View collection = " & IsObj($oApplicationViewCollection) & @CRLF) $oService.QueryService($tCLSID_VirtualDesktopManagerInternal, $tIID_IVirtualDesktopManagerInternal, $pVirtualDesktopManagerInternal) ConsoleWrite("Virtual Desktop pointer = " & $pVirtualDesktopManagerInternal & @CRLF) Local $oVirtualDesktopManagerInternal = ObjCreateInterface($pVirtualDesktopManagerInternal, $IID_IVirtualDesktopManagerInternal, $tagIVirtualDesktopManagerInternal) ConsoleWrite("Virtual Desktop = " & IsObj($oVirtualDesktopManagerInternal) & @CRLF) $oService.QueryService($tCLSID_VirtualDesktopPinnedApps, $tIID_IVirtualDesktopPinnedApps, $pVirtualDesktopPinnedApps) ConsoleWrite("Virtual Desktop Pinned Apps = " & $pVirtualDesktopPinnedApps & @CRLF) Local $oVirtualDesktopPinnedApps = ObjCreateInterface($pVirtualDesktopPinnedApps, $IID_IVirtualDesktopPinnedApps, $tagIVirtualDesktopPinnedApps) ConsoleWrite("Virtual Desktop Pinned Apps = " & IsObj($oVirtualDesktopPinnedApps) & @CRLF) Local $iCount, $pCurrent, $pLeft, $pNew, $iHresult, $hWnd, $pView, $pArray, $pDesktop, $oArray, $oView, $sView, $bValue ; gives the number of virtual desktops $iHresult = $oVirtualDesktopManagerInternal.GetCount($iCount) ConsoleWrite("Hello") ConsoleWrite("Number of Desktop = " & $iCount & "/" & $iHresult & @CRLF) If $iCount > 1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "Please close all additional Virtual Desktops") Func __uuidof($sGUID) Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]") DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID) If @error Then Return SetError(@error, @extended, 0) Return $tGUID EndFunc ;==>__uuidof Quote >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3" /UserParams +>18:07:11 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_11/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\misha\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\misha\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.16.0) from:C:\Program Files (x86)\AutoIt3 input:D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3 +>18:07:12 AU3Check ended.rc:0 >Running:(3.3.16.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test.au3" False--> SetHotKey Restart failed, Ctrl+BREAK to Stop. Immersive shell = 1 Service pointer = 1536583277240 Service = 1 View collection pointer = 1536583272760 View collection = 1 Virtual Desktop pointer = 1536583272872 Virtual Desktop = 1 Virtual Desktop Pinned Apps = 1536583273544 Virtual Desktop Pinned Apps = 1 !>18:07:13 AutoIt3.exe ended.rc:-1073741819 +>18:07:13 AutoIt3Wrapper Finished. >Exit code: 3221225477 Time: 3.329 Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2022 Author Share Posted May 25, 2022 Wonderful. It now creates the internal object correctly. I have just noticed that the GetCount method has changed, you need to provide a ptr/handle (of a window or a monitor ?), but I trust you can set it to 0 (default ?) Replace the GetCount method with this : "GetCount hresult(ptr;int*);" & _ And now use it like this : $iHresult = $oVirtualDesktopManagerInternal.GetCount(0, $iCount) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted May 26, 2022 Author Share Posted May 26, 2022 @ycomp After looking in more details, there is quite a large number of differences between Win10 and Win11 concerning the VirtualDesktopManagerInternal and other interfaces. Like I already said, I do not have a Win11 machine. So I will not embark in developing an example without proper testing. Maybe someone else could take the flambeau to adapt the code to the new OS. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ycomp Posted May 27, 2022 Share Posted May 27, 2022 (edited) 20 hours ago, Nine said: @ycomp After looking in more details, there is quite a large number of differences between Win10 and Win11 concerning the VirtualDesktopManagerInternal and other interfaces. Like I already said, I do not have a Win11 machine. So I will not embark in developing an example without proper testing. Maybe someone else could take the flambeau to adapt the code to the new OS. could you link to the specs/docs for virtual desktops on win11? also it wouldn't hurt for win10 as well so I can compare. I might be able to get the few methods I need working this way, given that I have your win10 autoit code already. wow, you're a genius) I have 11 desktops btw Quote >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test2.au3" /UserParams +>15:48:17 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_11/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\misha\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\misha\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.16.0) from:C:\Program Files (x86)\AutoIt3 input:D:\Trader Code\AutoIt\MP3 Show Tagger\source\test2.au3 +>15:48:18 AU3Check ended.rc:0 >Running:(3.3.16.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "D:\Trader Code\AutoIt\MP3 Show Tagger\source\test2.au3" False--> SetHotKey Restart failed, Ctrl+BREAK to Stop. Immersive shell = 1 Service pointer = 2500813679000 Service = 1 View collection pointer = 2500813675752 View collection = 1 Virtual Desktop pointer = 2500813678664 Virtual Desktop = 1 Virtual Desktop Pinned Apps = 2500813673512 Virtual Desktop Pinned Apps = 1 HelloNumber of Desktop = 11/0 ->15:48:21 AutoIt3.exe ended.rc:1 +>15:48:21 AutoIt3Wrapper Finished. >Exit code: 1 Time: 4.783 Edited May 27, 2022 by ycomp Link to comment Share on other sites More sharing options...
Nine Posted June 6, 2022 Author Share Posted June 6, 2022 @ycomp Most of the code I found is coming from github. You will need to translate the code into autoIt. Win10 and Win11 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
tantrim Posted November 4, 2022 Share Posted November 4, 2022 (edited) @ycomp I updated the script to work with Windows 11.@Nine I made the file compatible with both Windows 10 and Windows 11. Thanks for writing the script in the first place. Without the windows 10 version as a guide I would have been completely lost! Windows 11 Build >= 22489 VirtualDesktop11Insider.csWindows 11 Build < 22489VirtualDesktop11.cs UPDATE: they added another update to Windows 11 and added the GetAllCurrentDesktops method. Changes found in VirtualDesktop11Insider.cs Updated Code: expandcollapse popup#include <Constants.au3> ;https://github.com/MScholtes/VirtualDesktop/blob/master/VirtualDesktop11Insider.cs ;https://github.com/MScholtes/VirtualDesktop/blob/master/VirtualDesktop11.cs ;https://github.com/MScholtes/VirtualDesktop/blob/master/VirtualDesktop.cs Opt("MustDeclareVars", True) ; Windows 11 currently registers as Windows 10 in the registry. This script is compatible with both OS. This could break for Windows 11 in the future if Microsoft updates the registry for Windows 11 to reflect it's OS If @OSVersion <> "WIN_10" Then Exit MsgBox($MB_SYSTEMMODAL, "", "This script only runs on Win 10 and Win 11") Local $OSBuild = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild") Local Enum $windows10 = 21999, $windows11 = 22000 ;GetOS() ;OS Specific Variables Local $IID_IVirtualDesktop, $IID_IVirtualDesktopManagerInternal, $tagIVirtualDesktopManagerInternal If $OSBuild >= $windows11 Then $IID_IVirtualDesktop = "{536D3495-B208-4CC9-AE26-DE8111275BF8}" $IID_IVirtualDesktopManagerInternal = "{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}" If $OSBuild >= 22489 Then $tagIVirtualDesktopManagerInternal = _ "GetCount hresult(ptr;int*);" & _ "MoveViewToDesktop hresult(ptr;ptr);" & _ "CanViewMoveDesktops hresult(ptr;bool*);" & _ "GetCurrentDesktop hresult(ptr;ptr*);" & _ "GetAllCurrentDesktops hresult();" & _ "GetDesktops hresult(ptr;ptr*);" & _ "GetAdjacentDesktop hresult(ptr;int;ptr*);" & _ "SwitchDesktop hresult(ptr;ptr);" & _ "CreateDesktopW hresult(ptr;int*);" & _ "MoveDesktop hresult(ptr;int*;int);" & _ "RemoveDesktop hresult(ptr;ptr);" & _ "FindDesktop hresult(struct*;ptr*);" Else $tagIVirtualDesktopManagerInternal = _ "GetCount hresult(ptr;int*);" & _ "MoveViewToDesktop hresult(ptr;ptr);" & _ "CanViewMoveDesktops hresult(ptr;bool*);" & _ "GetCurrentDesktop hresult(ptr;ptr*);" & _ "GetDesktops hresult(ptr;ptr*);" & _ "GetAdjacentDesktop hresult(ptr;int;ptr*);" & _ "SwitchDesktop hresult(ptr;ptr);" & _ "CreateDesktopW hresult(ptr;int*);" & _ "MoveDesktop hresult(ptr;int*;int);" & _ "RemoveDesktop hresult(ptr;ptr);" & _ "FindDesktop hresult(struct*;ptr*);" EndIf ElseIf $OSBuild < $windows11 Then $IID_IVirtualDesktop = "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}" $IID_IVirtualDesktopManagerInternal = "{F31574D6-B682-4CDC-BD56-1827860ABEC6}" $tagIVirtualDesktopManagerInternal = _ "GetCount hresult(int*);" & _ "MoveViewToDesktop hresult(ptr;ptr);" & _ "CanViewMoveDesktops hresult(ptr;bool*);" & _ "GetCurrentDesktop hresult(ptr*);" & _ "GetDesktops hresult(ptr*);" & _ "GetAdjacentDesktop hresult(ptr;int;ptr*);" & _ "SwitchDesktop hresult(ptr);" & _ "CreateDesktopW hresult(int*);" & _ "RemoveDesktop hresult(ptr;ptr);" & _ "FindDesktop hresult(struct*;ptr*);" EndIf ; Instanciation objects Local $CLSID_ImmersiveShell = "{c2f03a33-21f5-47fa-b4bb-156362a2f239}" Local $IID_IUnknown = "{00000000-0000-0000-c000-000000000046}" Local $IID_IServiceProvider = "{6D5140C1-7436-11CE-8034-00AA006009FA}" Local $tIID_IServiceProvider = __uuidof($IID_IServiceProvider) Local $tagIServiceProvider = _ "QueryService hresult(struct*;struct*;ptr*);" ; VirtualDesktopManagerInternal object Const Enum $eLeftDirection = 3, $eRightDirection Local $CLSID_VirtualDesktopManagerInternal = "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}" Local $tCLSID_VirtualDesktopManagerInternal = __uuidof($CLSID_VirtualDesktopManagerInternal) Local $tIID_IVirtualDesktopManagerInternal = __uuidof($IID_IVirtualDesktopManagerInternal) ; ApplicationViewCollection object Local $CLSID_IApplicationViewCollection = "{1841C6D7-4F9D-42C0-AF41-8747538F10E5}" Local $tCLSID_IApplicationViewCollection = __uuidof($CLSID_IApplicationViewCollection) Local $IID_IApplicationViewCollection = "{1841C6D7-4F9D-42C0-AF41-8747538F10E5}" Local $tIID_IApplicationViewCollection = __uuidof($IID_IApplicationViewCollection) Local $tagIApplicationViewCollection = _ "GetViews hresult(struct*);" & _ "GetViewsByZOrder hresult(struct*);" & _ "GetViewsByAppUserModelId hresult(wstr;struct*);" & _ "GetViewForHwnd hresult(hwnd;ptr*);" & _ "GetViewForApplication hresult(ptr;ptr*);" & _ "GetViewForAppUserModelId hresult(wstr;int*);" & _ "GetViewInFocus hresult(ptr*);" ; ApplicationView object Local $IID_IApplicationView = "{372E1D3B-38D3-42E4-A15B-8AB2B178F513}" Local $tagIApplicationView = _ "GetIids hresult(ulong*;ptr*);" & _ "GetRuntimeClassName hresult(str*);" & _ "GetTrustLevel hresult(int*);" & _ "SetFocus hresult();" & _ "SwitchTo hresult();" & _ "TryInvokeBack hresult(ptr);" & _ "GetThumbnailWindow hresult(hwnd*);" & _ "GetMonitor hresult(ptr*);" & _ "GetVisibility hresult(int*);" & _ "SetCloak hresult(int;int);" & _ "GetPosition hresult(clsid;ptr*);" & _ "SetPosition hresult(ptr);" & _ "InsertAfterWindow hresult(hwnd);" & _ "GetExtendedFramePosition hresult(struct*);" & _ "GetAppUserModelId hresult(wstr*);" & _ "SetAppUserModelId hresult(wstr);" & _ "IsEqualByAppUserModelId hresult(wstr;int*);" & _ "GetViewState hresult(uint*);" & _ "SetViewState hresult(uint);" & _ "GetNeediness hresult(int*);" ; VirtualDesktopPinnedApps object Local $CLSID_VirtualDesktopPinnedApps = "{b5a399e7-1c87-46b8-88e9-fc5747b171bd}" Local $tCLSID_VirtualDesktopPinnedApps = __uuidof($CLSID_VirtualDesktopPinnedApps) Local $IID_IVirtualDesktopPinnedApps = "{4ce81583-1e4c-4632-a621-07a53543148f}" Local $tIID_IVirtualDesktopPinnedApps = __uuidof($IID_IVirtualDesktopPinnedApps) Local $tagIVirtualDesktopPinnedApps = _ "IsAppIdPinned hresult(wstr;bool*);" & _ "PinAppID hresult(wstr);" & _ "UnpinAppID hresult(wstr);" & _ "IsViewPinned hresult(ptr;bool*);" & _ "PinView hresult(ptr);" & _ "UnpinView hresult(ptr);" ; Miscellaneous objects Local $IID_IObjectArray = "{92ca9dcd-5622-4bba-a805-5e9f541bd8c9}" Local $tagIObjectArray = _ "GetCount hresult(int*);" & _ "GetAt hresult(int;ptr;ptr*);" Local $tIID_IVirtualDesktop = __uuidof($IID_IVirtualDesktop) ; Windows OS Specific Variable Local $tagIVirtualDesktop = _ "IsViewVisible hresult(ptr;bool*);" & _ "GetId hresult(clsid*);" ; objects creation Local $pService Local $oImmersiveShell = ObjCreateInterface($CLSID_ImmersiveShell, $IID_IUnknown, "") ConsoleWrite("Immersive shell = " & IsObj($oImmersiveShell) & @CRLF) $oImmersiveShell.QueryInterface($tIID_IServiceProvider, $pService) ConsoleWrite("Service pointer = " & $pService & @CRLF) Local $oService = ObjCreateInterface($pService, $IID_IServiceProvider, $tagIServiceProvider) ConsoleWrite("Service = " & IsObj($oService) & @CRLF) Local $pApplicationViewCollection, $pVirtualDesktopManagerInternal, $pVirtualDesktopPinnedApps $oService.QueryService($tCLSID_IApplicationViewCollection, $tIID_IApplicationViewCollection, $pApplicationViewCollection) ConsoleWrite("View collection pointer = " & $pApplicationViewCollection & @CRLF) Local $oApplicationViewCollection = ObjCreateInterface($pApplicationViewCollection, $IID_IApplicationViewCollection, $tagIApplicationViewCollection) ConsoleWrite("View collection = " & IsObj($oApplicationViewCollection) & @CRLF) $oService.QueryService($tCLSID_VirtualDesktopManagerInternal, $tIID_IVirtualDesktopManagerInternal, $pVirtualDesktopManagerInternal) ConsoleWrite("Virtual Desktop pointer = " & $pVirtualDesktopManagerInternal & @CRLF) Local $oVirtualDesktopManagerInternal = ObjCreateInterface($pVirtualDesktopManagerInternal, $IID_IVirtualDesktopManagerInternal, $tagIVirtualDesktopManagerInternal) ConsoleWrite("Virtual Desktop = " & IsObj($oVirtualDesktopManagerInternal) & @CRLF) $oService.QueryService($tCLSID_VirtualDesktopPinnedApps, $tIID_IVirtualDesktopPinnedApps, $pVirtualDesktopPinnedApps) ConsoleWrite("Virtual Desktop Pinned Apps = " & $pVirtualDesktopPinnedApps & @CRLF) Local $oVirtualDesktopPinnedApps = ObjCreateInterface($pVirtualDesktopPinnedApps, $IID_IVirtualDesktopPinnedApps, $tagIVirtualDesktopPinnedApps) ConsoleWrite("Virtual Desktop Pinned Apps = " & IsObj($oVirtualDesktopPinnedApps) & @CRLF) Local $iCount, $pCurrent, $pLeft, $pNew, $iHresult, $hWnd, $pView, $pArray, $pDesktop, $oArray, $oView, $sView, $bValue ; gives the number of virtual desktops ;$iHresult = ($OSBuild >= $windows11) ? $oVirtualDesktopManagerInternal.GetCount(0, $iCount) : $oVirtualDesktopManagerInternal.GetCount($iCount) $iCount = 1 ConsoleWrite("Number of Desktop = " & $iCount & "/" & $iHresult & @CRLF) ;If $iCount > 1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "Please close all additional Virtual Desktops") ; creates a new virtual desktop $iHresult = ($OSBuild >= $windows11) ? $oVirtualDesktopManagerInternal.CreateDesktopW(0, $pNew) : $oVirtualDesktopManagerInternal.CreateDesktopW($pNew) ConsoleWrite("Create = " & $pNew & "/" & $iHresult & @CRLF) $iHresult = ($OSBuild >= $windows11) ? $oVirtualDesktopManagerInternal.SwitchDesktop(0, $pNew) : $oVirtualDesktopManagerInternal.SwitchDesktop($pNew) ConsoleWrite("Switch = " & $iHresult & @CRLF) Run("Notepad.exe") WinWait("[CLASS:Notepad]") ; enumerates all desktops $iHresult = ($OSBuild >= $windows11) ? $oVirtualDesktopManagerInternal.GetDesktops(0, $pArray) : $oVirtualDesktopManagerInternal.GetDesktops($pArray) $oArray = ObjCreateInterface($pArray, $IID_IObjectArray, $tagIObjectArray) ConsoleWrite("Array = " & IsObj($oArray) & @CRLF) $oArray.GetCount($iCount) ConsoleWrite("Count = " & $iCount & @CRLF) $oArray.GetAt(0, DllStructGetPtr($tIID_IVirtualDesktop), $pDesktop) ConsoleWrite("Desktop 0 = " & $pDesktop & @CRLF) $oArray.GetAt(1, DllStructGetPtr($tIID_IVirtualDesktop), $pCurrent) ConsoleWrite("Desktop 1 = " & $pCurrent & @CRLF) ; gives the current desktop id $iHresult = ($OSBuild >= $windows11) ? $oVirtualDesktopManagerInternal.GetCurrentDesktop(0, $pCurrent) : $oVirtualDesktopManagerInternal.GetCurrentDesktop($pCurrent) ConsoleWrite("Current = " & $pCurrent & "/" & $iHresult & @CRLF) ; returns the adjacent desktop id $iHresult = $oVirtualDesktopManagerInternal.GetAdjacentDesktop($pCurrent, $eLeftDirection, $pLeft) ConsoleWrite("Get Left = " & $pLeft & "/" & $iHresult & @CRLF) ; switches to a specific desktop MsgBox ($MB_SYSTEMMODAL,"","Now it will return to previous desktop") Sleep(500) ; gives time for the msg box to close $iHresult = ($OSBuild >= $windows11) ? $oVirtualDesktopManagerInternal.SwitchDesktop(0, $pLeft) : $oVirtualDesktopManagerInternal.SwitchDesktop($pLeft) ConsoleWrite("Switch = " & $iHresult & @CRLF) ; get pointer to a view based on hwnd and create an application view $hWnd = WinGetHandle("[CLASS:Notepad]") $iHresult = $oApplicationViewCollection.GetViewForHwnd($hWnd, $pView) ConsoleWrite("View from handle = " & $pView & "/" & $iHresult & @CRLF) $oView = ObjCreateInterface($pView, $IID_IApplicationView, $tagIApplicationView) ConsoleWrite("Application view = " & IsObj($oView) & @CRLF) $iHresult = $oView.GetAppUserModelId($sView) ConsoleWrite("Get App ID = " & $sView & "/" & $iHresult & @CRLF) ; verify if app is pinned with ptr and string $iHresult = $oVirtualDesktopPinnedApps.IsViewPinned($pView, $bValue) ConsoleWrite("Is View Pinned = " & $bValue & "/" & $iHresult & @CRLF) $iHresult = $oVirtualDesktopPinnedApps.IsAppIdPinned($sView, $bValue) ConsoleWrite("Is AppId Pinned = " & $bValue & "/" & $iHresult & @CRLF) ; move application to a specific desktop $iHresult = $oVirtualDesktopManagerInternal.MoveViewToDesktop($pView, $pDesktop) ConsoleWrite("Move = " & $iHresult & @CRLF) Sleep(2000) ; deletes an existing desktop $iHresult = $oVirtualDesktopManagerInternal.RemoveDesktop($pNew, $pDesktop) ConsoleWrite("Delete = " & $iHresult & @CRLF) Func __uuidof($sGUID) Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]") DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID) If @error Then Return SetError(@error, @extended, 0) Return $tGUID EndFunc ;==>__uuidof Edited November 15, 2022 by tantrim mLipok 1 Link to comment Share on other sites More sharing options...
tantrim Posted November 5, 2022 Share Posted November 5, 2022 (edited) I'm trying to change the desktop I'm viewing to the desktop that a window currently resides on. Below is how to get the Desktop Object from a window handle. After I get the Desktop Object I can just use SwitchDesktop to change my view. Sadly I can't figure how to convert it to AutoIt. This is my first time ever working with COM, on C# or AutoIt so I am lacking a bit of fundamental knowledge. // get desktop from window handle try { // seeking desktop for window handle rc = VirtualDesktop.Desktop.FromDesktop(VirtualDesktop.Desktop.FromWindow((IntPtr)iParam)); if (verbose) Console.WriteLine("Window is on desktop number " + rc.ToString() + " (desktop '" + VirtualDesktop.Desktop.DesktopNameFromIndex(rc) + "')"); } catch { // error while seeking if (verbose) Console.WriteLine("Window to handle " + groups[2].Value + "' not found"); rc = -1; } EDIT: I figured out a workaround with WinActivate Edited November 6, 2022 by tantrim Link to comment Share on other sites More sharing options...
OvisMaximus Posted February 21, 2023 Share Posted February 21, 2023 Just started with AutoIt scripting to simplify my daily login routine. Move the windows to the appropriate desktop, correct monitor and resize them accordingly. To move the windows to an other desktop it needs the results of the discussion here. Sadly, the code is posted and scattered across this thread, so it took me some time to pull the threads together. Although I'm deeply convinced that I missed one or two things, one may find the result useful. https://github.com/OvisMaximus/WindowsDesktopAutomation/blob/main/VirtDsktLibrary.au3 mLipok and SOLVE-SMART 2 Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted February 21, 2023 Share Posted February 21, 2023 Thanks and welcome @OvisMaximus 👍 . I will review your code when I have the time - thanks for sharing. Btw.: I added you to this list. Best regards Sven OvisMaximus 1 Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now