jeeswg's Explorer tutorial

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

jeeswg's Explorer tutorial

14 May 2017, 14:27

QUICK TIPS

[hotkeys:]
left-click (or right-click) Start button: shutdown options
Win+R: Run dialog
Win+L: lock workstation
Ctrl+Alt+arrow: rotate the screen
Ctrl+Shift+Esc (or Ctrl+Alt+Del): Windows Task Manager

[Run dialog: strings to type:]
control hotplug.dll: Safely Remove Hardware
msinfo32: System Information
notepad: Notepad
sndvol (or sndvol32): Volume Mixer/Volume Control

see also: MORE TIPS section, lower down

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

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

Select a file by name:

Code: Select all

#IfWinActive ahk_class CabinetWClass
q:: ;explorer - select file by name
#IfWinActive ahk_class ExploreWClass
q:: ;explorer - select file by name
;where vName can be a name or path
vName := "New Text Document.txt"
;vName := A_Desktop "\New Text Document.txt"
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		;SVSI_FOCUSED := 0x10 ;SVSI_ENSUREVISIBLE := 0x8
		;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
		;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
		oItems := oWin.Document.Folder.Items
		try oWin.Document.SelectItem(vName, 0x1D)
		break
	}
}
oWin := ""
return
#IfWinActive
Create a new text file and focus/select it:

Code: Select all

#IfWinActive ahk_class CabinetWClass
q:: ;explorer - create new text file and focus/select it
#IfWinActive ahk_class ExploreWClass
q:: ;explorer - create new text file and focus/select it
;note: similar to: right-click, New, Text Document
vNameNoExt := "New Text Document"
vDotExt := ".txt"
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		vDir := RTrim(oWin.Document.Folder.Self.Path, "\")
		;if !DirExist(vDir)
		if !InStr(FileExist(vDir), "D")
		{
			oWin := ""
			return
		}

		Loop
		{
			vSfx := (A_Index=1) ? "" : " (" A_Index ")"
			vName := vNameNoExt vSfx vDotExt
			vPath := vDir "\" vName
			if !FileExist(vPath)
				break
		}

		;create a blank text file (ANSI/UTF-8/UTF-16)
		;FileAppend,, % "*" vPath
		FileAppend,, % "*" vPath, UTF-8
		;FileAppend,, % "*" vPath, UTF-16

		;SVSI_FOCUSED := 0x10 ;SVSI_ENSUREVISIBLE := 0x8
		;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
		;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
		Loop 30
		{
			if !(oWin.Document.Folder.Items.Item(vName).path = "")
			{
				oWin.Document.SelectItem(vPath, 0x1F)
				break
			}
			Sleep, 100
		}
		break
	}
}
oWin := ""
return
#IfWinActive
[set directory of Explorer window (to directory/shell command/CLSID)]
Navigate an Explorer object to a CLSID address - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=5592

Use a hotkey, e.g. Shift+Enter, to open a file/folder with a secondary program:
Quicker way to open script file for editing - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26638

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

PROCESS INFO

Code: Select all

q:: ;active process - get all info
WinGet, vPID, PID, A
oProcInfo := {}
for oProc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where ProcessId = " vPID)
{
	for oProp in ComObjGet("winmgmts:\\.\root\CIMV2:Win32_Process").Properties_
		vOutput .= oProp.Name "`t" oProc[oProp.Name] "`r`n"
}
oProc := oProp := ""
Clipboard := vOutput
MsgBox, % "done"
return

w:: ;all processes - get creation date (UTC)
oProcInfo := {}
for oProc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
	vOutput .= SubStr(oProc.CreationDate, 1, 14) "`t" oProc.Name "`r`n"
oProc := ""
Clipboard := vOutput
MsgBox, % "done"
return

e:: ;notepad processes - get creation date (UTC), PID, window title
oProcInfo := {}
vPName := "notepad.exe"
for oProc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name='" vPName "'")
{
	WinGetTitle, vWinTitle, % "ahk_class Notepad ahk_pid " oProc.ProcessID
	vOutput .= SubStr(oProc.CreationDate, 1, 14) "`t" oProc.ProcessID "`t" vWinTitle "`r`n"
}
oProc := ""
Clipboard := vOutput
MsgBox, % "done"
return

r:: ;processes with names containing 'pad' - get PID and name
;IWbemServices::ExecQuery (wbemcli.h) | Microsoft Docs
;https://docs.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemservices-execquery
;Querying with WQL - Windows applications | Microsoft Docs
;https://docs.microsoft.com/en-gb/windows/win32/wmisdk/querying-with-wql
for oProc in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE '%pad%'")
	MsgBox, % oProc.ProcessID "`t" oProc.Name
oProc := ""
return
==================================================

SPECIAL FOLDERS:

Code: Select all

;Run, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ;Computer (My Computer)
;Run, ::{645ff040-5081-101b-9f08-00aa002f954e} ;Recycle Bin
;Run, shell:MyComputerFolder ;Computer (My Computer)
;Run, shell:RecycleBinFolder ;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 (SHOW THE DESKTOP/MINIMISE ALL WINDOWS):

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
WIN+L (LOCK WORKSTATION):
[disable Win+L hotkey][define alternative hotkey]
locking my screen not with Win L - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=69537

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,,3" ;System Properties, Advanced tab ;(e.g. Performance, Settings..., Adjust for best performance)
;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

;e.g. DllCall equivalents:
;DllCall("shell32\Options_RunDLLW", "Ptr",0, "Ptr",0, "WStr","", "UInt",1) ;Folder Options, General tab
;DllCall("shell32\Options_RunDLLW", "Ptr",0, "Ptr",0, "WStr","7", "UInt",1) ;Folder Options, View tab
SHUTDOWN:

Code: Select all

;Run, % "rundll32 user32.dll,LockWorkStation" ;Win+L
;DllCall("user32\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, shell:ControlPanelFolder ;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

;if A_Is64bitOS && !(A_PtrSize=8) ;if 32-bit AHK on 64-bit PC
;	DllCall("kernel32\Wow64DisableWow64FsRedirection", "Ptr*",0)
;Run, explorer.exe shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8}\pageSettings ;Windows Update\Change settings

;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
;DllCall("shell32\Control_RunDLLW", "Ptr",0, "Ptr",0, "WStr","desk.cpl,,2", "UInt",1) ;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 ;Control Panel\Network and Internet\Network Connections
;Run, control netconnections ;Network Connections ;Control Panel\Network and Internet\Network Connections
;Run, ::{7007ACC7-3202-11D1-AAD2-00805FC1270E} ;Network Connections
;Run, shell:ConnectionsFolder ;Control Panel\All Control Panel Items\Network Connections

;Run, shell:NetworkPlacesFolder ;Network

;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
==================================================

RUN CLSIDs

In the examples above, there were subtle differences in the code required to run a CLSID:

Code: Select all

;4 levels of complexity:
;Run, ::{MyCLSID}
;Run, shell:::{MyCLSID}
;Run, explorer.exe shell:::{MyCLSID}
;Run, explorer.exe shell:::{MyCLSID} ;plus call Wow64DisableWow64FsRedirection (if 32-bit AHK on 64-bit PC)

;Run, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ;My Computer
;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, ::{645ff040-5081-101b-9f08-00aa002f954e} ;Recycle Bin
;Run, ::{7007ACC7-3202-11D1-AAD2-00805FC1270E} ;Network Connections

;Run, shell:::{025A5937-A6BE-4686-A844-36FE4BEC8B6D}\pagePlanSettings ;Power Options\Edit Plan Settings
;Run, shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0} ;Win+R Run dialog
;Run, shell:::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5} ;Programs and Features (Uninstall or change a program)
;Run, shell:::{8E908FC9-BECC-40F6-915B-F4CA0E70D03D} ;Network and Sharing Center
;Run, shell:::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE} ;System

;Run, explorer.exe shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8} ;Windows Update
;Run, explorer.exe shell:::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921} ;Control Panel\Appearance and Personalization\Personalization

;if A_Is64bitOS && !(A_PtrSize=8) ;if 32-bit AHK on 64-bit PC
;	DllCall("kernel32\Wow64DisableWow64FsRedirection", "Ptr*",0)
;Run, explorer.exe shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8}\pageSettings ;Windows Update\Change settings
==================================================

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

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

MORE 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/efficiently-change-a-single-file-extension-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/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

q:: ;toggle hide/show extensions (tested on Windows 7)
;SSF_SHOWALLOBJECTS := 0x1
vNum := 0x1
DllCall("shell32\SHGetSetSettings", "Ptr",&SHELLSTATE, "UInt",vNum, "Int",0)
vState := NumGet(SHELLSTATE, "UInt")
NumPut(vState ? 0 : vNum, SHELLSTATE, "UInt")
DllCall("shell32\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\SHGetSetSettings", "Ptr",&SHELLSTATE, "UInt",vNum, "Int",0)
vState := NumGet(SHELLSTATE, "UInt")
NumPut(vState ? 0 : vNum, SHELLSTATE, "UInt")
DllCall("shell32\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/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

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

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

MOVE OFF-SCREEN DESKTOP ICONS BACK TO VISIBLE AREA

note: you may want to take a printscreen, to backup the icon order, before moving icons

4 approaches:

[set icon size from medium to small to medium]
right-click, View, small icons
right-click, View, medium icons
the off-screen icons appear as a column on the right-hand side

[cut and paste]
[note: perhaps TeraCopy interferes with (blocks) this]
press right, to select an off-screen icon
press the Menu key, Cut
move the cursor (to a suitable location)
right-click, Paste

[auto-arrange icons]
[warning: this changes the order]
right-click, View, tick Auto arrange icons

[change listview item coordinates via LVM_SETITEMPOSITION]
[x64 & x32 fix] DeskIcons - Get/Set Desktop Icon Positions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=3529

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

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
GUIs via DllCall: text functions (get/set internal/external control text) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40514

[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

[set taskbar position]
Taskbar - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=59239&p=251311#p251311

[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

[hide/show tray icons]
Is there a way to put an icon outside the hidden tray icons by default? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=58992

[remove systray icons for processes that were abruptly closed]
How to remove systray icon after process was closed? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=69887

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

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

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

GET DESKTOP ICON INFO

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

[get access to the desktop shell object]
Create new file in current explorer window? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=9618&p=53361#p53361

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

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

Code: Select all

;e.g. columns:
;prop:System.ItemNameDisplay; ;Name
;prop:System.DateModified; ;Date modified
;prop:System.DateCreated; ;Date created
;prop:System.ItemTypeText; ;Type
;prop:System.Size; ;Size

#IfWinActive ahk_class CabinetWClass
q:: ;explorer - sort files by date modified
#IfWinActive ahk_class ExploreWClass
q:: ;explorer - sort files by date modified
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		MsgBox, % oWin.Document.SortColumns ;show current sort columns
		;oWin.Document.SortColumns := "prop:System.DateModified;" ;sort by date modified ascending (oldest first)
		oWin.Document.SortColumns := "prop:-System.DateModified;" ;sort by date modified descending (newest first)
		;oWin.Document.SortColumns := "prop:System.ItemNameDisplay;" ;sort by name ascending (A-Z)
		;oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ;sort by name descending (A-Z)
		break
	}
}
oWin := ""
return
#IfWinActive
==================================================

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

;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

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("kernel32\GetSystemDefaultUILanguage", "UShort")
vLanguage := Format("{:04X}", vLanguage)

;A_ComputerName
;MAX_COMPUTERNAME_LENGTH := 31
VarSetCapacity(vComputerName, 32*2)
vSize := 32
DllCall("kernel32\GetComputerName", "Str",vComputerName, "UInt*",vSize)

;A_UserName
;UNLEN := 256
VarSetCapacity(vUserName, 257*2)
vSize := 257
DllCall("advapi32\GetUserName", "Str",vUserName, "UInt*",vSize)

;A_WinDir
;MAX_PATH := 260
VarSetCapacity(vWinDir, 260*2)
DllCall("kernel32\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/library/windows/desktop/ms683156(v=vs.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.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

;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-commands-to-access-the-special-folders/

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

WINDOW EVENTS

[SetWinEventHook]
Event Constants (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066(v=vs.85).aspx
Simple File Explorer Fix - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=48911&p=219950#p219950
Is possible to get path when Explorer window is closing and restore when is opening? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=49842&p=221423#p221423
Trouble getting shellhook to detect window change - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=51265&p=226227#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

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

LAUNCH/RELOAD SCRIPT AS ADMIN/NON-ADMIN (RUN AS ADMINISTRATOR)

Reloading: Admin to Non-Admin - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=7752

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

SCREEN BRIGHTNESS

3 ways to dim the screen - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39580

Brightness adjust via scroll wheel - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=69857

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

ENABLE/DISABLE WINDOWS UPDATE

Code: Select all

;open Windows Update\Change settings (tested on Windows 7)
DllCall("kernel32\Wow64DisableWow64FsRedirection", "Ptr*",0)
Run, explorer.exe shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8}\pageSettings
return
;under 'Important updates', choose from the drop-down list

;or, less direct:
;open Windows Update\Change settings (tested on Windows 7)
Run, control /name Microsoft.WindowsUpdate ;Windows Update
return
;then manually click 'Change settings'
;under 'Important updates', choose from the drop-down list
==================================================

CHKDSK

Explorer: list chkdsk results - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=62719

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

REFRESH EXPLORER

Refreshing the file explorer - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=12656
(solved) How do I update explorer/windows with registry changes? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=14567
Getting explorer to 'reload' registry changes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39494&p=180845#p180845

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

CLIPBOARD

Various threads are listed here:
jeeswg's homepage - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=17&t=30931&p=144437#p144437

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

RE-ENABLE HARDWARE AFTER HIBERNATING PC

[re-enable USB mouse after hibernating PC]
USB mouse stops working after hibernating PC - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=64809

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

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 22 Nov 2019, 08:45, edited 80 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
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: 78
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: 6902
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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
drozdman
Posts: 78
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: 586
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.
neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: jeeswg's Explorer tutorial

23 Mar 2019, 17:48

jeeswg, or anyone else reading, do you know a PostMessage or other method to *read* the current sort mode from an Explorer Window? Both which column is used to sort and which order of ascending/descending.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Explorer tutorial

23 Mar 2019, 18:17

- @neogna2: Here's a COM object approach, based on drozdman's script above. I don't know about PostMessage/SendMessage.
- The text tells you which columns are used to order the files. A minus sign is present if descending order is used (i.e. Z-A).

Code: Select all

;e.g. prop:System.ItemNameDisplay; ;sorted by Name ascending (A-Z)
;e.g. prop:-System.ItemNameDisplay; ;sorted by Name descending (Z-A)

q:: ;Explorer - get sort columns
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
	if (oWin.HWND = hWnd)
	{
		MsgBox, % oWin.Document.SortColumns
		break
	}
oWin := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: jeeswg's Explorer tutorial

24 Mar 2019, 04:20

jeeswg wrote:
23 Mar 2019, 18:17
- @neogna2: Here's a COM object approach
Thank you!
Klarion
Posts: 176
Joined: 26 Mar 2019, 10:02

Re: jeeswg's Explorer tutorial

10 May 2019, 08:56

nice
eekhelpspike
Posts: 20
Joined: 05 Jul 2015, 17:51

Re: jeeswg's Explorer tutorial

01 Aug 2019, 13:54

Not sure why, but I can't get anything to select using the first example in this thread. I even tried creating a file names "New Text Document.txt" and it won't select that either, as well as just making a file called "new" and making that the target instead. It activates windows explorer after I press the hotkey. I'm on 1903. Does the preview pane affect it at all, or any other of the changeable "views" options in explorer?

And thanks, jesswg. I feel like I've used your help a lot lately via these posts.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's Explorer tutorial

01 Aug 2019, 18:49

- It worked for me just now on Windows 7. For Windows 10, you could try running the script as admin, or maybe someone else with Windows 10 could test the script.
- You could also add this line, to test it's working:
MsgBox, % oWin.Document.Folder.Items.Count
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
eekhelpspike
Posts: 20
Joined: 05 Jul 2015, 17:51

Re: jeeswg's Explorer tutorial

02 Aug 2019, 06:00

jeeswg wrote:
01 Aug 2019, 18:49
- It worked for me just now on Windows 7. For Windows 10, you could try running the script as admin, or maybe someone else with Windows 10 could test the script.
- You could also add this line, to test it's working:
MsgBox, % oWin.Document.Folder.Items.Count
I just tried running as admin on another Win10 machine, as well as running as admin. Same lack of result. The file count message box does work, though.

I found one of your posts regarding selecting a "random" file, and this does work.

Code: Select all

q:: ;Explorer window/Desktop - focus a random file
;get Explorer object for active window:
if !oWin := JEE_ExpWinGetObj()
	return
vCount := oWin.Document.Folder.Items.Count
Random, vNum, 1, % vCount

;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8
;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
oItems := oWin.Document.Folder.Items
if vCount
	oWin.Document.SelectItem(oItems.Item(vNum-1), 0x1D)
oWin := oItems := ""
return

JEE_ExpWinGetObj(hWnd:=0)
{
	DetectHiddenWindows, On
	(!hWnd) && hWnd := WinExist("A")
	WinGetClass, vWinClass, % "ahk_id " hWnd
	if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
	{
		for oWin2 in ComObjCreate("Shell.Application").Windows
			if (oWin2.HWND = hWnd)
			{
				oWin := oWin2
				break
			}
	}
	else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
	{
		oWindows := ComObjCreate("Shell.Application").Windows
		VarSetCapacity(hWnd, 4, 0)
		;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1
		oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1)
	}
	return oWin
}
This from another thread works as well:

Code: Select all

controlsend,DirectUIHWND3 ,%n% , ahk_class CabinetWClass
I'll just use this last one until I run into an issue with it. Thanks for your help.
eekhelpspike
Posts: 20
Joined: 05 Jul 2015, 17:51

Re: jeeswg's Explorer tutorial

02 Aug 2019, 06:55

Nevermind- That doesn't seem to work either. It apparently only selects based on the first character, so a file starting with the letter "N" would be selectable if all the other files started with something other than "N". Ugh.
eekhelpspike
Posts: 20
Joined: 05 Jul 2015, 17:51

Re: jeeswg's Explorer tutorial

02 Aug 2019, 07:47

Argh. I just had to be using the full file name including path. I wish I would've tried that first before bothering you. Sorry! Thanks again.
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: jeeswg's Explorer tutorial

30 Jan 2020, 22:28

This is alot of very useful information! Thank you!
rhythmhighnoonstone
Posts: 11
Joined: 13 Jan 2021, 01:04

Re: jeeswg's Explorer tutorial

05 Mar 2021, 22:14

Hello jeeswg! Hope you're doing well. I'm writing to express my gratitude for all of your ahk articles and forum replies. [How to remove empty lines at the end of Clipboard?](https://www.autohotkey.com/boards/viewtopic.php?t=38016) is very useful for my script; then I benefited a lot from this particular reply of yours: [ControlSend and windows internet explorer problem](https://www.autohotkey.com/boards/viewtopic.php?t=37345)

I was trying to do exactly what the OP was trying to do, and your code snippet just made my day! I wouldn't have figured out the code myself, so thank you! It's an amazing feeling getting ahk to work as intended!
mmmax
Posts: 81
Joined: 25 Jun 2018, 09:01

Re: jeeswg's Explorer tutorial

20 Oct 2023, 15:19

My v2 script to toggle sorting ascending/descending by either name, date modified, or size:

Code: Select all

#HotIf WinActive("ahk_exe explorer.exe|ahk_class CabinetWClass")
;███;EXPLORER█████████████████████████████████████████████
	; shift ctrl/win alt 1 - explorer sort by name
	+^!1::
	^#!1::
	{
		HotKeyWait()
		;columns:
		;Name			=	prop:System.ItemNameDisplay;
		;Date modified	=	prop:System.DateModified;
		;Date created	=	prop:System.DateCreated;
		;Type			=	prop:System.ItemTypeText;
		;Size			=	prop:System.Size;

		;oWin.Document.SortColumns := "prop:System.DateModified;" ;sort by date modified ascending (oldest first)
		;oWin.Document.SortColumns := "prop:System.ItemNameDisplay;" ;sort by name ascending (A-Z)
		;oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ;sort by name descending (A-Z)

		hWnd := WinGetID("A")
		for oWin in ComObject("Shell.Application").Windows
		{
			if (oWin.HWND = hWnd)
			{
				MyTip("Current Sort Order: " oWin.Document.SortColumns, -3000) ;show current sort columns
				if oWin.Document.SortColumns != "prop:System.ItemNameDisplay;"
				{
					oWin.Document.SortColumns := "prop:+System.ItemNameDisplay;" ;sort by date modified descending (newest first)
				}
				else if oWin.Document.SortColumns == "prop:System.ItemNameDisplay;"
				{
					oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ;sort by date modified descending (newest first)	
				}
				break
			}
		}
		oWin := ""
		return
	}

;███;EXPLORER█████████████████████████████████████████████
	; shift ctrl/win alt 5 - explorer sort by date modified
	+^!5::
	^#!5::
	{
		HotKeyWait()
		;columns:
		;Name			=	prop:System.ItemNameDisplay;
		;Date modified	=	prop:System.DateModified;
		;Date created	=	prop:System.DateCreated;
		;Type			=	prop:System.ItemTypeText;
		;Size			=	prop:System.Size;

		;oWin.Document.SortColumns := "prop:System.DateModified;" ;sort by date modified ascending (oldest first)
		;oWin.Document.SortColumns := "prop:System.ItemNameDisplay;" ;sort by name ascending (A-Z)
		;oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ;sort by name descending (A-Z)

		hWnd := WinGetID("A")
		for oWin in ComObject("Shell.Application").Windows
		{
			if (oWin.HWND = hWnd)
			{
				MyTip("Current Sort Order: " oWin.Document.SortColumns, -3000) ;show current sort columns
				if oWin.Document.SortColumns != "prop:-System.DateModified;"
				{
					oWin.Document.SortColumns := "prop:-System.DateModified;" ;sort by date modified descending (newest first)
				}
				else if oWin.Document.SortColumns == "prop:-System.DateModified;"
				{
					oWin.Document.SortColumns := "prop:+System.DateModified;" ;sort by date modified descending (newest first)	
				}
				break
			}
		}
		oWin := ""
		return
	}

;███;EXPLORER█████████████████████████████████████████████
	; shift ctrl/win alt 6 - explorer sort by size
	+^!6::
	^#!6::
	{
		HotKeyWait()
		;columns:
		;Name			=	prop:System.ItemNameDisplay;
		;Date modified	=	prop:System.DateModified;
		;Date created	=	prop:System.DateCreated;
		;Type			=	prop:System.ItemTypeText;
		;Size			=	prop:System.Size;

		;oWin.Document.SortColumns := "prop:System.DateModified;" ;sort by date modified ascending (oldest first)
		;oWin.Document.SortColumns := "prop:System.ItemNameDisplay;" ;sort by name ascending (A-Z)
		;oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ;sort by name descending (A-Z)

		hWnd := WinGetID("A")
		for oWin in ComObject("Shell.Application").Windows
		{
			if (oWin.HWND = hWnd)
			{
				MyTip("Current Sort Order: " oWin.Document.SortColumns, -3000) ;show current sort columns
				if oWin.Document.SortColumns != "prop:-System.Size;"
				{
					oWin.Document.SortColumns := "prop:-System.Size;" ;sort by date modified descending (newest first)
				}
				else if oWin.Document.SortColumns == "prop:-System.Size;"
				{
					oWin.Document.SortColumns := "prop:+System.Size;" ;sort by date modified descending (newest first)	
				}
				break
			}
		}
		oWin := ""
		return
	}
#HotIf
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: jeeswg's Explorer tutorial

28 Jan 2024, 06:10

Let me add Hide and Show for the ToolbarWindow32x Control to this wonderful jeeswg's Explorer tutorial.
Hide:

Code: Select all

SendMessage 0x111, 0x500,, "ToolbarWindow323", "ahk_class CabinetWClass"
Show:

Code: Select all

SendMessage 0x111, 0x501,, "ToolbarWindow323", "ahk_class CabinetWClass"
P.s.: v2!

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 33 guests