IGRACH
IGRACH

Reputation: 3635

Close windows explorer window with Auto hotkey

I'm unable to find method to close path open in windows explorer. Lets say I would like to close opened window, "c:\program files". Code should look like

#::j

    close window "c:\program files"

return 

Thank you.

Upvotes: 0

Views: 2052

Answers (2)

errorseven
errorseven

Reputation: 2672

Updated Code and here is a video stepping through the code:

path := "C:\Program Files"

shell := ComObjCreate("Shell.Application")
shell.open("file:///c:/")
shell.open("file:///" . path) 


#If WinExist("ahk_class CabinetWClass") ; explorer

    F1::
    for window in ComObjCreate("Shell.Application").Windows
       if (path == window.Document.Folder.Self.Path)
            window.quit()
    return

#If

Upvotes: 0

PGilm
PGilm

Reputation: 2312

You will want to look here:

https://autohotkey.com/docs/commands/WinClose.htm

which specifies:

WinClose [, WinTitle, WinText, SecondsToWait, ExcludeTitle, ExcludeText]

and then:

#j::  ;  Win Key + j
    WinClose, C:\Program Files  ;  close Program Files window
return

Alternatively, to close any explorer window, use:

#j::  ;  Win Key + j
    WinClose, ahk_class CabinetWClass  ;  closes any explorer window
return

Hth

Upvotes: 1

Related Questions