Activating a File Explorer tab in Windows 11

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
user44321
Posts: 8
Joined: 04 Mar 2023, 15:40

Activating a File Explorer tab in Windows 11

Post by user44321 » 04 Mar 2023, 15:47

Hey there. I've modified a script I found online, which loops among all the file explorer tabs.
The only thing I'm missing is a way to activate that tab.
With WinActivate, the File Explorer is activated, showing its current tab, not the one returned by the loop.

Do you know how to activate the returned tab?

Code: Select all

getFileExplorerTab(path) {
    
	hwnd := WinExist("A")
	activeTab := 0
	
    try activeTab := ControlGetHwnd("ShellTabWindowClass1", hwnd) ; File Explorer (Windows 11)
	
    for w in ComObject("Shell.Application").Windows 
	{
		
		if (w.LocationURL == path) {
			return w
		}
		
        if w.hwnd != hwnd
            continue
        if activeTab { ; The window has tabs, so make sure this is the right one.
            static IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}"
            shellBrowser := ComObjQuery(w, IID_IShellBrowser, IID_IShellBrowser)
            ComCall(3, shellBrowser, "uint*", &thisTab:=0)
            if thisTab != activeTab
                continue
        
        }
    }
	
	msgbox('end')
}

tab := getFileExplorerTab('file:///C:/Users/Ivo/Downloads')

if(tab)
{
	msgbox(tab.LocationURL)
	WinActivate(tab)
}
else
{
	msgbox('tab is null')
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Activating a File Explorer tab in Windows 11

Post by swagfag » 11 Mar 2023, 18:48

id look for new COM interfaces in Windows11 exposing such an action(ie activating a specified tab)
otherwise, u can probably do it by enumerating the tabs with UIA and sending some clicks to whichever one u want activated

shtirlits_dva
Posts: 7
Joined: 20 Jan 2023, 06:05
Contact:

Re: Activating a File Explorer tab in Windows 11

Post by shtirlits_dva » 24 Mar 2023, 05:57

swagfag wrote:
11 Mar 2023, 18:48
id look for new COM interfaces in Windows11 exposing such an action(ie activating a specified tab)
otherwise, u can probably do it by enumerating the tabs with UIA and sending some clicks to whichever one u want activated
Where do you look for such COM interfaces?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Activating a File Explorer tab in Windows 11

Post by swagfag » 24 Mar 2023, 08:53

in order of easiest to hardest
  • on MSDN(assuming its even documented yet/at all)
  • u can diff the win10 sdk and the win11 sdk and see what changed(assuming its even exposed yet/at all)
  • if u can find a windows action that triggers the tab, u can attach a debugger and disassemble to see what functions are called
  • u can disassemble and check for known COM interfaces whether pointers to new undocumented vtables have been introduced(assuming they have been, to begin with)

Post Reply

Return to “Ask for Help (v2)”