jeeswg's Explorer tutorial

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 4492
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's Explorer tutorial

14 May 2017, 14:27

GET/SET FOLDER/FOCUS/SELECTION, CREATE NEW FILE/FOLDER:
Explorer folder windows/Desktop, file/folder interaction - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=35041

SPECIAL FOLDERS:

Code: [Select all] [Download] GeSHi © Codebox Plus

;Run, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ;My Computer
;Run, ::{645ff040-5081-101b-9f08-00aa002f954e} ;Recycle Bin


DESKTOP:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



WIN+D AND WIN+M:

Code: [Select all] [Download] GeSHi © Codebox Plus

;PostMessage, 0x111, 415,,, ahk_class Shell_TrayWnd ;WM_COMMAND ;Win+M?
;PostMessage, 0x111, 416,,, ahk_class Shell_TrayWnd ;WM_COMMAND ;Shift+Win+M? restore all
;PostMessage, 0x111, 419,,, ahk_class Shell_TrayWnd ;WM_COMMAND ;show desktop (doesn't toggle)
;PostMessage, 0x111, 407,,, ahk_class Shell_TrayWnd ;WM_COMMAND ;Win+D? show desktop toggle


WINDOWS / DIALOG BOXES:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



SHUTDOWN:

Code: [Select all] [Download] GeSHi © Codebox Plus

;Run, % "rundll32 user32.dll,LockWorkStation" ;Win+L
;DllCall("powrprof\SetSuspendState", UChar,0, UChar,0, UChar,0, UChar) ;Sleep/Suspend
;DllCall("powrprof\SetSuspendState", UChar,1, UChar,0, UChar,0, UChar) ;Hibernate
;Shutdown
;https://autohotkey.com/docs/commands/Shutdown.htm


CONTROL PANEL:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



UTILITIES:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



MONITORS:

Code: [Select all] [Download] GeSHi © Codebox Plus

;RunWait, displayswitch /internal ;Computer only/Disconnect Projector
;RunWait, displayswitch /clone ;Duplicate
;RunWait, displayswitch /extend ;Extend
;RunWait, displayswitch /external ;Projector only


==================================================

EXPLORER WINDOWS (FOLDERS/SPECIAL FOLDERS/CONTROL PANEL)

Code: [Select all] [Download] GeSHi © Codebox Plus

;based on:
;Getting CLSID or SpecialFolderConstant of an Explorer object - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=4884

q:: ;get the path for folders/special folders/Control Panel items
for window in ComObjCreate("Shell.Application").Windows
try MsgBox % window.Document.Folder.Self.Path
return


==================================================

EXPLORER MENU ITEMS

- You use PostMessage (or SendMessage to wait for a notification that the message has been received), with WM_COMMAND, and the correct menu item ID.
- I would experiment by sending messages to the Explorer folder window, and also to its controls.
- This script can be used to retrieve the menu item IDs for a menu:
Get Info from Context Menu (x64/x32 compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31971
- Note: some menu item IDs are constant, but others change each time, and some require that the menu be initialised (e.g. you nudge/refresh the menu via WM_INITMENU).

Code: [Select all] [Download] GeSHi © Codebox Plus

;PostMessage, 0x111, 41249,, ShellTabWindowClass1, A ;WM_COMMAND := 0x111 ;Back
;PostMessage, 0x111, 41250,, ShellTabWindowClass1, A ;WM_COMMAND := 0x111 ;Forward
;PostMessage, 0x111, 40994,, ShellTabWindowClass1, A ;WM_COMMAND := 0x111 ;Up one level

;PostMessage, 0x111, 28705,, SHELLDLL_DefView1, A ;Select all
;PostMessage, 0x111, 28706,, SHELLDLL_DefView1, A ;Invert Selection
;PostMessage, 0x111, 28747,, SHELLDLL_DefView1, A ;View, Details
;PostMessage, 0x111, 28753,, SHELLDLL_DefView1, A ;View, List
;PostMessage, 0x111, 31492,, SHELLDLL_DefView1, A ;View, Sort by, Name ;toggle ascending/descending


[trigger Explorer menu items]
Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27564

==================================================

EXPLORER FOLDER WINDOW MESSAGES / VIEW MODES

Code: [Select all] [Download] GeSHi © Codebox Plus

;q:: ;Explorer folder window messages (tested on Windows 7)
ControlGet, hCtl, Hwnd,, SHELLDLL_DefView1, A

PostMessage, 0x111, 28706, 0,, % "ahk_id " hCtl ;edit, invert selection
PostMessage, 0x111, 28747, 0,, % "ahk_id " hCtl ;view, details
PostMessage, 0x111, 28753, 0,, % "ahk_id " hCtl ;view, list
PostMessage, 0x111, 28705, 0,, % "ahk_id " hCtl ;edit, select all
PostMessage, 0x111, 31492, 0,, % "ahk_id " hCtl ;view, sort by, name
return


Code: [Select all] [Download] GeSHi © Codebox Plus

;q:: ;Explorer folder window messages (tested on Windows XP)
WinGet, hWnd, ID, A

PostMessage, 0x111, 28706, 0,, % "ahk_id " hWnd ;edit, invert selection
PostMessage, 0x111, 28716, 0,, % "ahk_id " hWnd ;view, details
PostMessage, 0x111, 28715, 0,, % "ahk_id " hWnd ;view, list
PostMessage, 0x111, 28705, 0,, % "ahk_id " hWnd ;edit, select all
return


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



[view modes]
IFolderView::SetCurrentViewMode method (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775618(v=vs.85).aspx
FOLDERVIEWMODE enumeration (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762510(v=vs.85).aspx

[lists of Explorer window message IDs (general comments + Windows XP constants)]
Automating Windows Explorer - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/5936-automating-windows-explorer/

[note: some IDs in context menus are constant, some are variable]
Get Info from Context Menu (x64/x32 compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31971

[set view mode via objects]
Reading Win 10 File Explorer View Mode - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28304

==================================================

FILE ICONS

[show/hide hidden files, show/hide extensions (via SHGetSetSettings)]
[refresh thumbnails/icons][when icons/thumbnails out-of-date][windows 7]
Refreshing the file explorer - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=12656
AutoHotkey_L v1.1.08 - Page 3 - Announcements - AutoHotkey Community
https://autohotkey.com/board/topic/82612-autohotkey-l-v1108/page-3#entry536021

==================================================

HIDE/SHOW EXTENSIONS, HIDE/SHOW HIDDEN FILES

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



==================================================

HIDE/SHOW DESKTOP ICONS

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



The wParam value 29698 is from:
Show/hide desktop icons in Windows 7 - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/43524-showhide-desktop-icons-in-windows-7/

On Windows 7, the 'Show desktop icons' menu item ID was 30988, but this didn't work as the wParam value.

==================================================

REFRESH DESKTOP/FOLDER ICONS

Code: [Select all] [Download] GeSHi © Codebox Plus

q:: ;refresh desktop/folder icons (tested on Windows 7)
;e.g. on Desktop: icons for files no longer on Desktop, disappear
;however on Desktop: thumbnails for images inside folders not updated
;SHCNE_ASSOCCHANGED := 0x8000000
DllCall("Shell32\SHChangeNotify", Int,0x8000000, UInt,0, Ptr,0, Ptr,0)
return


AutoHotkey_L v1.1.08 - Page 3 - Announcements - AutoHotkey Community
https://autohotkey.com/board/topic/82612-autohotkey-l-v1108/page-3#entry536021

==================================================

TASKBAR + SYSTRAY (TASKBAR BUTTONS + SYSTRAY ICONS)

[list taskbar buttons + systray icons]
Windows Update: detect if important updates available - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26727
[list taskbar windows (get hWnds)][list taskbar buttons]
Recover accidentally closed window/program - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=31704

[list information from tray icons][TrayIcon.ahk]
[LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=1229

[check for Windows updates including in systray]
Windows Update: detect if important updates available - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26727

[move mouse to taskbar button]
Move mouse to taskbar to use AeroPeek - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27147

[get/set taskbar auto-hide/lock states]
Get taskbar autohide state? Solved - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39123&p=179081#p179081

[group taskbar buttons: always/never combine]
Getting explorer to 'reload' registry changes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39494&p=180845#p180845

==================================================

RECENT ITEMS (MY RECENT DOCUMENTS)

list Recent Items (My Recent Documents) (Start Menu) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31386
Start menu, Recent Items menu, focus first/last item - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27560

==================================================

DESKTOP

get full paths of selected files on Desktop and Common File Dialogs - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=31135

==================================================

EXPLORER WINDOWS: COLUMNS

Explorer column interaction (get/set: which appear, width, ascending/descending order) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=33129

==================================================

DIALOGS

[get a single Properties dialog for multiple files (that don't have to be in the same folder)]
SHMultiFileProperties - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=30483

==================================================

FILE PROPERTIES

[check FileXXX functions]
Alphabetical Command and Function Index
https://autohotkey.com/docs/commands/

Loop (files & folders)
https://autohotkey.com/docs/commands/LoopFile.htm

[get file properties via objects e.g. length (duration), image dimensions]
[uses ComObjCreate("Shell.Application") and GetDetailsOf]
FileGetProperties - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/63697-filegetproperties/

==================================================

WINDOW THEME

simple method:

Code: [Select all] [Download] GeSHi © Codebox Plus

;Run, C:\Windows\Resources\Ease of Access Themes\classic.theme
;Run, C:\Users\%A_UserName%\AppData\Local\Microsoft\Windows\Themes\Custom.theme


Change Theme with RunDll32 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=31343
[better method]
Change w7 theme (for automatic postinstall) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=18879&p=91548#p91548

==================================================

COMMAND PROMPT (CMD)

Code: [Select all] [Download] GeSHi © Codebox Plus

q:: ;run cmd (hidden)
vUrl := "https://www.google.com/"
Run, cmd.exe /c start "C:\Program Files\Internet Explorer\iexplore.exe" "%vUrl%",, Hide
return

w:: ;run cmd (keep open)
vUrl := "https://www.google.com/"
Run, cmd.exe /k start "C:\Program Files\Internet Explorer\iexplore.exe" "%vUrl%"
return


==================================================

ARRANGE WINDOWS

Code: [Select all] [Download] GeSHi © Codebox Plus

;PostMessage, 0x111, 403, 0,, ahk_class Shell_TrayWnd ;Cascade windows
;PostMessage, 0x111, 404, 0,, ahk_class Shell_TrayWnd ;Show windows side by side ;(tile horizontally) (tile as columns)
;PostMessage, 0x111, 405, 0,, ahk_class Shell_TrayWnd ;Show windows stacked ;(tile vertically) (tile as rows)
;PostMessage, 0x111, 416, 0,, ahk_class Shell_TrayWnd ;Undo ;(undo cascade/tile)


==================================================

RETRIEVE THE CONTENTS OF AUTOHOTKEY'S 'A_' VARIABLES DIRECTLY

[A_ComSpec/A_Temp/A_Language/A_ComputerName/A_UserName/A_WinDir]
[A_AppData/A_Desktop/A_MyDocuments/A_ProgramFiles/A_Programs/A_StartMenu/A_Startup]
[also: environment variables, Recent folder path]
[note: A_Programs and A_Startup are Start menu folders]

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



==================================================

LIST ENVIRONMENT VARIABLES

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


[get the output from a console application]
jeeswg's documentation extension tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=33596

==================================================

COMMAND LINE: TASK MANAGER: SHOW COLUMN

To show the Command Line column in Task Manager:
if the Command Line column is not visible in the 'Processes' tab,
go to 'View, Select Columns...' and tick 'Command Line'.

==================================================

COMMAND LINE: RETRIEVE COMMAND-LINE STRING FOR A WINDOW

Note: MSDN uses the term 'command-line string' here:
GetCommandLine function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156(v=vs.85).aspx

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



==================================================

PROCESS NAME GET PATH

Best way to get the path to an executable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36484&p=168051#p168051
Best way to find an executable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=44630&p=202086#p202086

useful registry keys:
HKEY_CLASSES_ROOT\Applications
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



==================================================

WINDOWS FOLDER LOCATIONS (WINDOWS XP/WINDOWS 7)

- Note: you can paste these into the address bar of an Explorer window or into the Run dialog (which you can show by pressing Win+R).
- Environment variables like %appdata%, %temp%, %username%, and 'shell:' folders like shell:Desktop will be resolved.

Windows XP folders:
A_AppData = C:\Documents and Settings\%username%\Application Data
A_AppDataCommon = C:\Documents and Settings\All Users\Application Data
A_Desktop = C:\Documents and Settings\%username%\Desktop
A_DesktopCommon = C:\Documents and Settings\All Users\Desktop
A_MyDocuments = C:\Documents and Settings\%username%\My Documents
A_ProgramFiles = C:\Program Files
A_Programs = C:\Documents and Settings\%username%\Start Menu\Programs
A_ProgramsCommon = C:\Documents and Settings\All Users\Start Menu\Programs
A_StartMenu = C:\Documents and Settings\%username%\Start Menu
A_StartMenuCommon = C:\Documents and Settings\All Users\Start Menu
A_Startup = C:\Documents and Settings\%username%\Start Menu\Programs\Startup
A_StartupCommon = C:\Documents and Settings\All Users\Start Menu\Programs\Startup
A_Temp = C:\DOCUME~1\%username%\LOCALS~1\Temp
A_WinDir = C:\WINDOWS
Recent = C:\Documents and Settings\%username%\Recent

Windows 7 folders:
A_AppData = C:\Users\%username%\AppData\Roaming
A_AppDataCommon = C:\ProgramData
A_Desktop = C:\Users\%username%\Desktop
A_DesktopCommon = C:\Users\Public\Desktop
A_MyDocuments = C:\Users\%username%\Documents
A_ProgramFiles = C:\Program Files
A_Programs = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
A_ProgramsCommon = C:\ProgramData\Microsoft\Windows\Start Menu\Programs
A_StartMenu = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu
A_StartMenuCommon = C:\ProgramData\Microsoft\Windows\Start Menu
A_Startup = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
A_StartupCommon = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
A_Temp = C:\Users\%username%\AppData\Local\Temp
A_WinDir = C:\Windows
Recent = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Recent

'shell:' folders:
note: 'shell:MyComputerFolder' doesn't work on Windows XP
note: there is no 'shell:Temp' shortcut
A_AppData = shell:AppData
A_AppDataCommon = shell:Common AppData
A_Desktop = shell:Desktop
A_DesktopCommon = shell:Common Desktop
A_MyDocuments = shell:Personal
A_ProgramFiles = shell:ProgramFiles
A_Programs = shell:Programs
A_ProgramsCommon = shell:Common Programs
A_StartMenu = shell:Start Menu
A_StartMenuCommon = shell:Common Start Menu
A_Startup = shell:Startup
A_StartupCommon = shell:Common Startup
A_Temp = %temp%
A_WinDir = shell:Windows
MyComputer = shell:MyComputerFolder
Recent = shell:Recent

Link with more 'shell:' folders:
Shell Commands to Access the Special Folders in Windows 10/8/7/Vista/XP » Winhelponline
http://www.winhelponline.com/blog/shell-commands-to-access-the-special-folders/

==================================================

RESOURCES

C:\Windows\diagnostics (e.g. on Windows 7)
contains useful ps1 files, which can be translated to AHK for achieving certain tasks:
e.g. C:\Windows\diagnostics\system\AERO\CL_Utility.ps1, see:
Change w7 theme (for automatic postinstall) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=18879&p=91548#p91548

==================================================

MORE LINKS (SEE 'SHELL - ')

best utilities + best AutoHotkey scripts (+ useful tips) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=28149
Last edited by jeeswg on 13 Jun 2018, 05:27, edited 36 times in total.
ahkloverboy

Re: jeeswg's Explorer tutorial

14 Jul 2017, 18:46

thanks for putting these together.
plz bring up more noob tutorials by example, really appreciate em :bravo:

; Show Desktop (same as Send, #d) does toggle
Run shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}

; "Tile Vertically"
PostMessage, 0x111, 405, 0,, ahk_class Shell_TrayWnd

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 4 guests