Selecting a file in Windows Explorer is slow Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hilbert
Posts: 2
Joined: 18 Nov 2023, 14:58

Selecting a file in Windows Explorer is slow

Post by hilbert » 18 Nov 2023, 15:21

Hi,

Need to select a file in Windows Explorer. The following approach works but is slow. Takes at least 2-3 seconds for the window to appear (tried on several machines).

Code: Select all

Run Format("explorer.exe /select, `"{1}`"", path)
Are there better performing alternatives to achieve the same?

byzod
Posts: 89
Joined: 21 Jun 2021, 06:46

Re: Selecting a file in Windows Explorer is slow

Post by byzod » 19 Nov 2023, 06:07

It might be unrelated but I have the slow startup issue with xnview, find the solution after 7 years: add xnview.exe to exception of windows defender

How fast do your ahk runs the first time? If it's slow, you might want to try add autohotkey.exe to exception of your antivirus software

User avatar
mikeyww
Posts: 27241
Joined: 09 Sep 2014, 18:38

Re: Selecting a file in Windows Explorer is slow

Post by mikeyww » 19 Nov 2023, 08:17

You can run File Explorer earlier, and then just activate the window when you need it.

hilbert
Posts: 2
Joined: 18 Nov 2023, 14:58

Re: Selecting a file in Windows Explorer is slow

Post by hilbert » 20 Nov 2023, 12:10

mikeyww wrote:
19 Nov 2023, 08:17
You can run File Explorer earlier, and then just activate the window when you need it.
Thanks for answer. I don't have prior knowledge of which file to be selected, so can't run explorer earlier.
Or perhaps what you mean is to somehow issue 'please select this file in a new window' command to an already running explorer process? Because, as you probably aware, each "Run explorer.exe ..." creates a new explorer.exe process, which is likely to be the cause of latency.

neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: Selecting a file in Windows Explorer is slow

Post by neogna2 » 20 Nov 2023, 12:27

You can use COM to select one or more files in an existing File Explorer window.
https://learn.microsoft.com/en-us/windows/win32/shell/shellfolderview-selectitem
Search the forums with keyword "selectitem" to find existing code.

User avatar
mikeyww
Posts: 27241
Joined: 09 Sep 2014, 18:38

Re: Selecting a file in Windows Explorer is slow  Topic is solved

Post by mikeyww » 20 Nov 2023, 12:30

Code: Select all

#Requires AutoHotkey v2.0
nav

F3::nav(A_ScriptDir)

nav(dir := '') {
 Static winTitle := 'ahk_class CabinetWClass'
 If !WinExist(winTitle)
  Run 'explorer'
 If WinWait(winTitle,, 5) {
  If dir {
   WinActivate
   For window in ComObject('Shell.Application').Windows
    (WinActive('A') = window.Hwnd) && window.Navigate(dir)
  } Else WinMinimize
 } Else MsgBox 'An error occurred while waiting for the window.', 'Error', 48
}

Post Reply

Return to “Ask for Help (v2)”