jeeswg's Explorer tutorial

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 5448
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

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

Code: Select all

;Tested on Windows 7.

;combined A_Desktop and A_DesktopCommon
Run, "%A_Desktop%"
;Run, "C:\Users\%A_UserName%\Desktop"
;Run, explore "%A_Desktop%"
;Run, shell:Desktop

;A_Desktop only
Run, explorer.exe "%A_Desktop%"
;Run, explorer.exe "C:\Users\%A_UserName%\Desktop"
;Run, "C:\Documents and Settings\%A_UserName%\Desktop"

;A_DesktopCommon only
Run, "%A_DesktopCommon%"
;Run, C:\Users\Public\Desktop
WIN+D AND WIN+M:

Code: Select all

;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

;PostMessage, 0x111, 401,,, ahk_class Shell_TrayWnd ;WM_COMMAND ;Win+R Run dialog
;Run, Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0} ;Win+R Run dialog
;PostMessage, 0x111, 41093,,, ahk_class Shell_TrayWnd ;WM_COMMAND ;Win+F Search Results
;Run, taskmgr ;Ctrl+Shift+Esc Windows Task Manager
;Run, control hotplug.dll ;Safely Remove Hardware (e.g. Windows XP)
;Run, sndvol32 ;Volume Control (e.g. Windows XP)
;Run, sndvol ;Volume Mixer (e.g. Windows 7)
;Run, C:\Windows\System32\SndVol.exe ;Volume Mixer (e.g. Windows 7)
;Run, msinfo32 ;System Information
;Run, intl.cpl ;Region and Language
;Run, timedate.cpl ;Date and Time

;Run, sysdm.cpl ;System Properties, Computer Name tab
;Run, % "control sysdm.cpl,,2" ;System Properties, Hardware tab ;tab may not show
;Run, % "control sysdm.cpl,,3" ;System Properties, Advanced tab ;(e.g. Environment Variables)
;Run, % "control sysdm.cpl,,4" ;System Properties, System Protection tab ;tab may not show
;Run, % "control sysdm.cpl,,5" ;System Properties, Remote tab

;Run, mmsys.cpl ;Sound, Playback tab
;Run, % "control mmsys.cpl,,1" ;Sound, Recording tab
;Run, % "control mmsys.cpl,,2" ;Sound, Sounds tab
;Run, % "control mmsys.cpl,,3" ;Sound, Communications tab

;Run, % "rundll32 shell32.dll,Options_RunDLL" ;Folder Options, General tab
;Run, % "rundll32 shell32.dll,Options_RunDLL 7" ;Folder Options, View tab
;Run, % "rundll32 shell32.dll,Options_RunDLL 2" ;Folder Options, Search tab

;Run, % "rundll32 shell32.dll,Options_RunDLL 1" ;Taskbar and Start Menu Properties, Taskbar tab
;Run, % "rundll32 shell32.dll,Options_RunDLL 3" ;Taskbar and Start Menu Properties, Start Menu tab
;Run, % "rundll32 shell32.dll,Options_RunDLL 6" ;Taskbar and Start Menu Properties, Toolbars tab

;Run, % "rundll32 shell32.dll,Options_RunDLL 5" ;Control Panel\All Control Panel Items\Notification Area Icons
;Run, % "rundll32 shell32.dll,Options_RunDLL 4" ;Control Panel\All Control Panel Items\Notification Area Icons\System Icons
SHUTDOWN:

Code: Select all

;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

;Run, control ;Control Panel (view: Category/Large icons/small icons)
;Run, ::{26EE0668-A00A-44D7-9371-BEB064C98683} ;Control Panel (view: Category)

;Run, ::{26EE0668-A00A-44D7-9371-BEB064C98683}\0 ;Control Panel\All Control Panel Items ;(view: Large icons/Small icons)

;Run, control /name Microsoft.WindowsUpdate ;Windows Update
;Run, explorer.exe Shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8} ;Windows Update

;Run, control /name Microsoft.PowerOptions /page pagePlanSettings ;Power Options\Edit Plan Settings
;Run, Shell:::{025A5937-A6BE-4686-A844-36FE4BEC8B6D}\pagePlanSettings ;Power Options\Edit Plan Settings

;Run, % "control desk.cpl,,2" ;Control Panel\Appearance and Personalization\Personalization
;Run, % "rundll32 shell32.dll,Control_RunDLL desk.cpl,,2" ;Control Panel\Appearance and Personalization\Personalization
;Run, explorer.exe Shell:::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921} ;Control Panel\Appearance and Personalization\Personalization

;Run, desk.cpl ;Control Panel\Appearance and Personalization\Display\Screen Resolution
;Run, % "control desk.cpl,,0" ;Desktop Icon Settings
;Run, % "control desk.cpl,,1" ;Screen Saver Settings
;Run, % "control desk.cpl,,2" ;Control Panel\Appearance and Personalization\Personalization
;Run, % "control desk.cpl,,5" ;Window Color and Appearance

;Run, control system ;System
;Run, control /name Microsoft.System ;System
;Run, Shell:::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE} ;System

;Run, control /name Microsoft.NetworkAndSharingCenter ;Network and Sharing Center
;Run, Shell:::{8E908FC9-BECC-40F6-915B-F4CA0E70D03D} ;Network and Sharing Center

;Run, ncpa.cpl ;Network Connections
;Run, control netconnections ;Network Connections
;Run, ::{7007ACC7-3202-11D1-AAD2-00805FC1270E} ;Network Connections

;Run, appwiz.cpl ;Programs and Features (Uninstall or change a program)
;Run, Shell:::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5} ;Programs and Features (Uninstall or change a program)
UTILITIES:

Code: Select all

;non-obvious names
;Run, calc ;Calculator
;Run, charmap ;Character Map
;Run, cmd ;Command Prompt
;Run, mspaint ;Paint
;Run, winword ;Microsoft Word

;obvious names
;Run, excel ;Microsoft Excel
;Run, notepad ;Notepad
;Run, wordpad ;WordPad
MONITORS:

Code: Select all

;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

;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 oWin in ComObjCreate("Shell.Application").Windows
	try MsgBox % oWin.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

;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

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

SHELL CONTEXT MENUS AND THE SENDTO FOLDER

[how to add items to shell context menus]
[the SendTo folder can be used to launch a program with the selected files as arguments]
Explorer context menu shell extensions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=32152

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

TIPS

DRAG-AND-DROP TIP (DRAG TO TITLE BAR)

- If you compare Windows XP and Windows 7, it's harder to drag-and-drop files from one folder to another.
- This is because 'full row select' mode was added to the 'Details' view in Windows 7 (or perhaps Windows Vista). I.e. you can't simply drag-and-drop files to empty space, each bit of empty space is associated with a file (it is part of a row that extends from left-to-right).
- You could accidentally add a file to an archive, or launch an application, for example.
- A workaround is to drag-and-drop files to the title bar.

COPY AS PATH

- From Windows Vista onwards, you can select some files and do shift+right-click, or shift+Menu key to show a menu, and then choose 'Copy as path' to put the paths of the selected files onto the clipboard.

CHANGE A FILE'S EXTENSION (RENAME A FILE'S EXTENSION)

- Run cmd.exe, type ren, press space, and drag-and-drop a file onto the command prompt window.
- See the answers by vafylec and Synetech for more details:
Efficiently change a single file extension in Windows - Super User
https://superuser.com/questions/248501/ ... in-windows

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

EXPLORER FOLDER WINDOW MESSAGES / VIEW MODES

Code: Select all

;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

;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

;Windows 7 view modes
;menu item ID, view mode, CurrentViewMode/IconSize
;28749 E&xtra large icons - 1 256
;28751 La&rge icons - 1 96
;28750 &Medium icons - 1 48
;28752 Small ico&ns - 2 16
;28753 &List - 3 16
;28747 &Details - 4 16
;28748 Tile&s - 6 16
;28754 Conten&t - 8 32

q:: ;windows 7 - set view mode
ControlGet, hCtl, Hwnd,, SHELLDLL_DefView1, A
PostMessage, 0x111, 28747, 0,, % "ahk_id " hCtl ;View, Details
;PostMessage, 0x111, 28753, 0,, % "ahk_id " hCtl ;View, List
return

w:: ;windows 7 - set view mode
WinGet, hWnd, ID, A
WinGetClass, vWinClass, % "ahk_id " hWnd
if !(vWinClass = "CabinetWClass") && !(vWinClass = "ExploreWClass")
	return
for oWin in ComObjCreate("Shell.Application").Windows
	if (oWin.HWND = hWnd)
	{
		;MsgBox, % oWin.Document.CurrentViewMode " " oWin.Document.IconSize
		oWin.Document.CurrentViewMode := 4 ;View, Details
		;oWin.Document.CurrentViewMode := 3 ;View, List
		oWin.Document.IconSize := 16
		break
	}
oWin := ""
return
[view modes]
IFolderView::SetCurrentViewMode method (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
FOLDERVIEWMODE enumeration (Windows)
https://msdn.microsoft.com/en-us/librar ... s.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 ... -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/8261 ... ntry536021

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

HIDE/SHOW EXTENSIONS, HIDE/SHOW HIDDEN FILES

Code: Select all

q:: ;toggle hide/show extensions (tested on Windows 7)
;SSF_SHOWALLOBJECTS := 0x1
vNum := 0x1
DllCall("Shell32.dll\SHGetSetSettings", Ptr,&SHELLSTATE, UInt,vNum, Int,0)
vState := NumGet(SHELLSTATE, "UInt")
NumPut(vState ? 0 : vNum, SHELLSTATE, "UInt")
DllCall("Shell32.dll\SHGetSetSettings", Ptr,&SHELLSTATE, UInt,vNum, Int,1)

;refresh Desktop/folder windows (appeared to work for hide/show extensions, but not hide/show hidden files)
SHCNE_ASSOCCHANGED := 0x8000000
DllCall("Shell32\SHChangeNotify", Int,0x8000000, UInt,0, Ptr,0, Ptr,0)
return

Code: Select all

q:: ;toggle hide/show hidden files (tested on Windows 7)
;SSF_SHOWEXTENSIONS := 0x2
vNum := 0x2
VarSetCapacity(SHELLSTATE, 36, 0)
DllCall("Shell32.dll\SHGetSetSettings", Ptr,&SHELLSTATE, UInt,vNum, Int,0)
vState := NumGet(SHELLSTATE, "UInt")
NumPut(vState ? 0 : vNum, SHELLSTATE, "UInt")
DllCall("Shell32.dll\SHGetSetSettings", Ptr,&SHELLSTATE, UInt,vNum, Int,1)

;refresh Desktop/folder windows
DetectHiddenWindows, On
GroupAdd, WinGroupFolder, ahk_class CabinetWClass
GroupAdd, WinGroupFolder, ahk_class ExploreWClass
PostMessage, 0x111, 28931,, SHELLDLL_DefView1, ahk_class Progman
WinGet, vWinList, List, ahk_group WinGroupFolder
Loop, % vWinList
	PostMessage, 0x111, 41504,, ShellTabWindowClass1, % "ahk_id " vWinList%A_Index%
	;PostMessage, 0x111, 28931,, SHELLDLL_DefView1, % "ahk_id " vWinList%A_Index% ;also works
return
==================================================

HIDE/SHOW DESKTOP ICONS

Code: Select all

q:: ;toggle hide/show desktop icons (tested on windows 7)
PostMessage, 0x111, 29698,, SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
return

w:: ;show desktop icons (tested on windows 7)
ControlGet, vCtlStyle, Style,, SysListView321, ahk_class Progman
if !(vCtlStyle & 0x10000000) ;WS_VISIBLE := 0x10000000
	PostMessage, 0x111, 29698,, SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
return

e:: ;hide desktop icons (tested on windows 7)
ControlGet, vCtlStyle, Style,, SysListView321, ahk_class Progman
if (vCtlStyle & 0x10000000) ;WS_VISIBLE := 0x10000000
	PostMessage, 0x111, 29698,, SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
return
The wParam value 29698 is from:
Show/hide desktop icons in Windows 7 - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/4352 ... 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

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/8261 ... ntry536021

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

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)]
  • Recover accidentally closed window/program - AutoHotkey Community
    https://autohotkey.com/boards/viewtopic.php?f=5&t=31704
    • [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 ... 81#p179081

      [set taskbar position]
      Taskbar - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 11#p251311

      [group taskbar buttons: always/never combine]
      Getting explorer to 'reload' registry changes - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 45#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/6369 ... roperties/

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

      WINDOW THEME

      simple method:

      Code: Select all

      ;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 ... 548#p91548

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

      COMMAND PROMPT (CMD)

      Code: Select all

      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

      ;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)
      
      ;note: the terms 'tile horizontally' and 'tile vertically' are confusing and often used to mean opposites
      ;'tile as columns' and 'tile as rows' are more sensible
      ;https://www.safaribooksonline.com/library/view/filemaker-pro-9/9780596514136/httpatomoreillycomsourceoreillyimages44774.png
      
      ;note: these numbers (tested on Windows 7) differ from those obtained by querying the context menu (on Windows 7):
      
      ;404	Cascade windows
      ;406	Show windows stacked
      ;405	Show windows side by side
      ;408	Show the desktop
      
      ;421	Start Task Manager
      
      ;425	Lock the taskbar
      ;414	Properties
      
      ==================================================

      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

      q:: ;retrieve contents of 'A_' variables directly (based on AHK v1.1 source code)
      ;A_ComSpec (ComSpec)
      VarSetCapacity(vText, 0x7FFF*2)
      vVarName := "ComSpec"
      DllCall("kernel32\GetEnvironmentVariable", Str,vVarName, Str,vText, UInt,0x7FFF, UInt)
      vComSpec := vText
      
      ;A_Temp
      ;MAX_PATH := 260
      VarSetCapacity(vTemp, 261*2)
      DllCall("kernel32\GetTempPath", UInt,261, Str,vTemp, UInt)
      vTemp := RTrim(vTemp, "\")
      
      ;A_Language
      vLanguage := DllCall("GetSystemDefaultUILanguage")
      vLanguage := Format("{:04X}", vLanguage)
      
      ;A_ComputerName
      ;MAX_COMPUTERNAME_LENGTH := 31
      VarSetCapacity(vComputerName, 32*2)
      vSize := 32
      DllCall("kernel32\GetComputerName", Str,vComputerName, UIntP,vSize)
      
      ;A_UserName
      ;UNLEN := 256
      VarSetCapacity(vUserName, 257*2)
      vSize := 257
      DllCall("advapi32\GetUserName", Str,vUserName, UIntP,vSize)
      
      ;A_WinDir
      ;MAX_PATH := 260
      VarSetCapacity(vWinDir, 260*2)
      DllCall("GetWindowsDirectory", Str,vWinDir, UInt,260, UInt)
      
      ;A_AppData/A_AppDataCommon
      ;A_Desktop/A_DesktopCommon
      ;A_MyDocuments
      ;A_ProgramFiles (ProgramFiles)
      ;A_Programs/A_ProgramsCommon
      ;A_StartMenu/A_StartMenuCommon
      ;A_Startup/A_StartupCommon
      
      ;CSIDL_APPDATA := 26 ;CSIDL_COMMON_APPDATA := 35
      ;CSIDL_DESKTOPDIRECTORY := 16 ;CSIDL_COMMON_DESKTOPDIRECTORY := 25
      ;CSIDL_MYDOCUMENTS := 5
      ;CSIDL_PROGRAM_FILES := 38
      ;CSIDL_PROGRAMS := 2 ;CSIDL_COMMON_PROGRAMS := 23
      ;CSIDL_STARTMENU := 11 ;CSIDL_COMMON_STARTMENU := 22
      ;CSIDL_STARTUP := 7 ;CSIDL_COMMON_STARTUP := 24
      
      ;(note: there is no 'A_Recent' variable at present)
      ;CSIDL_RECENT := 8
      
      ;SHGFP_TYPE_CURRENT := 0
      oArray := {AppData:26,AppDataCommon:35,Desktop:16,DesktopCommon:25,MyDocuments:5,ProgramFiles:38,Programs:2,ProgramsCommon:23,StartMenu:11,StartMenuCommon:22,Startup:7,StartupCommon:24}
      oArray["Recent"] := 8
      for vKey, vNum in oArray
      {
      	VarSetCapacity(vPath, 261*2)
      	DllCall("shell32\SHGetFolderPath", Ptr,0, Int,vNum, Ptr,0, UInt,0, Str,vPath)
      	v%vKey% := vPath
      }
      MsgBox, % vRecent
      
      vList := "ComSpec,Temp,Language,ComputerName,UserName,WinDir,AppData,AppDataCommon,Desktop,DesktopCommon,MyDocuments,ProgramFiles,Programs,ProgramsCommon,StartMenu,StartMenuCommon,Startup,StartupCommon"
      vOutput := ""
      Loop, Parse, vList, % ","
      {
      	vTemp2 := "A_" A_LoopField
      	if (%vTemp2% = "")
      		vTemp2 := A_LoopField
      	vOutput .= (A_Index=1?"":"`r`n") vTemp2 "`r`n" %vTemp2% "`r`n" v%A_LoopField% "`r`n"
      }
      Clipboard := vOutput
      MsgBox, % vOutput
      return
      
      ==================================================

      LIST ENVIRONMENT VARIABLES

      Code: Select all

      q:: ;list environment variables
      DetectHiddenWindows, On
      Run, % ComSpec,, Hide, vPID
      WinWait, % "ahk_pid " vPID
      DllCall("kernel32\AttachConsole", UInt,vPID)
      oShell := ComObjCreate("WScript.Shell")
      oExec := oShell.Exec(ComSpec " /c set")
      vStdOut := ""
      while !oExec.StdOut.AtEndOfStream
      	vStdOut := oExec.StdOut.ReadAll()
      Clipboard := vStdOut
      DllCall("kernel32\FreeConsole")
      Process, Close, % vPID
      MsgBox, % vStdOut
      return
      
      [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/librar ... s.85).aspx

      Code: Select all

      ;e.g. retrieve command-line string for active window
      ;WinGet, vPID, PID, A
      ;MsgBox, % JEE_ProcessGetCommandLine(vPID)
      JEE_ProcessGetCommandLine(vPIDOrName:="")
      {
      	if !vPID := ProcessExist(vPIDOrName)
      		return
      	oWMI := ComObjGet("winmgmts:")
      	oQueryEnum := oWMI.ExecQuery("Select * from Win32_Process where ProcessId=" vPID)._NewEnum()
      	if oQueryEnum[oProcess]
      		vCmdLn := oProcess.CommandLine
      	oWMI := oQueryEnum := oProcess := ""
      	return vCmdLn
      }
      
      ==================================================

      PROCESS NAME GET PATH

      Best way to get the path to an executable - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 51#p168051
      Best way to find an executable - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 86#p202086

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

      Code: Select all

      ;e.g. get process path
      RegRead, vPath, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE
      MsgBox, % vPath
      
      ;e.g. get multiple process paths
      vList := "chrome.exe,firefox.exe,iexplore.exe"
      vOutput := ""
      Loop, Parse, vList, % ","
      {
      	vName := A_LoopField
      	RegRead, vPath, % "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" vName
      	vOutput .= vName "`t" vPath "`r`n"
      }
      MsgBox, % vOutput
      
      ;e.g. get multiple process paths
      vOutput := ""
      oArray := []
      Loop, Reg, % "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths", K
      {
      	RegRead, vPath, % A_LoopRegKey "\" A_LoopRegSubkey "\" A_LoopRegName
      	oArray.Push(A_LoopRegName "`t" vPath)
      }
      Loop, % vIndex := oArray.Length()
      	vOutput .= oArray[vIndex--] "`r`n"
      Clipboard := vOutput
      MsgBox, % vOutput
      return
      
      ==================================================

      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 ... l-folders/

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

      WINDOW EVENTS

      [SetWinEventHook]
      Event Constants (Windows)
      https://msdn.microsoft.com/en-us/librar ... s.85).aspx
      Simple File Explorer Fix - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 50#p219950
      Is possible to get path when Explorer window is closing and restore when is opening? - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 23#p221423
      Trouble getting shellhook to detect window change - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic ... 27#p226227

      [WMI events e.g. WmiMonitorBrightnessEvent]
      Detect screen brightness changes in Windows 10 - AutoHotkey Community
      https://autohotkey.com/boards/viewtopic.php?f=5&t=58914

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

      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 ... 548#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 04 Dec 2018, 08:00, edited 46 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
drozdman
Posts: 68
Joined: 05 Dec 2015, 01:07

Re: jeeswg's Explorer tutorial

30 Aug 2018, 15:02

I can add this. Sorting in "Windows Explorer". I'm using it in this Toolbar for 'Windows Explorer', although I didn't update it yet.

Code: Select all

~^g:: Gosub, test

test:
 WinGet, Win_id , ID, A

  win := GetShellFolder(Win_id)
  win.Document.SortColumns:="prop:-System.DateModified;"   ; sort - from newest
	sleep 1000
  win.Document.SortColumns:="prop:System.ItemTypeText;"   ; sort - type 
	sleep 1000
  win.Document.SortColumns:="prop:+System.ItemNameDisplay;"  ; sort ascending A-Z  
return

GetShellFolder(Win_id){
    for win in ComObjCreate("Shell.Application").Windows  {
			if(win.HWND && win.HWND == Win_id){
				return win
			}
		}			
}


;win.Document.SortColumns:="prop:-System.DateModified;"   ; sort - from newest
;win.Document.SortColumns:="prop:+System.DateModified;"   ; sort - from oldest

;win.Document.SortColumns:="prop:-System.ItemNameDisplay;"  ; sort descending Z-A
;win.Document.SortColumns:="prop:+System.ItemNameDisplay;"  ; sort ascending A-Z

;win.Document.SortColumns:="prop:-System.Size;"   ; sort - from largest
;win.Document.SortColumns:="prop:+System.Size;"   ; sort - from smallest

;win.Document.SortColumns:="prop:-System.DateCreated;"   ; sort - from newest
;win.Document.SortColumns:="prop:+System.DateCreated;"   ; sort - from oldest


Esc:: 
ExitApp
User avatar
jeeswg
Posts: 5448
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Explorer tutorial

30 Aug 2018, 15:51

- Thanks ahkloverboy.

- Many thanks for your script drozdman. Much appreciated.
- This does certain things far more simply than my current approaches:
Explorer column interaction (get/set: which appear, width, ascending/descending order) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=33129
- Any info about how you came across this? Thanks.
drozdman
Posts: 68
Joined: 05 Dec 2015, 01:07

Re: jeeswg's Explorer tutorial

30 Aug 2018, 16:26

@jeeswg
I studied the Microsoft website documentation. And I checked what's inside the object in every case of sort.
Links:
https://docs.microsoft.com/en-us/window ... sortcolumn
https://docs.microsoft.com/en-us/window ... rviewdual3
neogna2
Posts: 25
Joined: 15 Sep 2016, 15:44

Re: jeeswg's Explorer tutorial

09 Dec 2018, 05:43

jeeswg wrote:
14 May 2017, 14:27

Code: Select all

;PostMessage, 0x111, 31492,, SHELLDLL_DefView1, A ;View, Sort by, Name ;toggle ascending/descending
In Windows 10 that message toggles sort ascending/descending for the first column whichever column that is.
For example if the user has dragged to rearrange columns so that the Type column is first then the Type column sort direction is toggled by the command, not the Name column.

Similarly 31493 toggles sort ascending/descending for the second column, 31494 for the third, and so on.
PostMessage, 0x111, 31492,, SHELLDLL_DefView1, A ;toggle Explorer sort column 1 ascending/descending
PostMessage, 0x111, 31493,, SHELLDLL_DefView1, A ;toggle Explorer sort column 2 ascending/descending
PostMessage, 0x111, 31494,, SHELLDLL_DefView1, A ;toggle Explorer sort column 3 ascending/descending
PostMessage, 0x111, 31495,, SHELLDLL_DefView1, A ;toggle Explorer sort column 4 ascending/descending
This means that variants of this message can make a Windows 10 File Explorer window sort the folder contents by Name, Type, Date modified, Size, Date created, Authors, Title and so on.

This also means that a script that in part changes the Explorer sort order must, in order to be portable between different PCs, add steps that first checks the Explorer column order on the current PC and then sends the correct message based on that information.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 7 guests