Refreshing the file explorer

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
manosathya98
Posts: 4
Joined: 04 Jan 2016, 08:56

Refreshing the file explorer

04 Jan 2016, 10:08

I am using two scripts which toggle file extensions and hidden files in the file explorer, however the changes only come into effect when I refresh the screen.

Here are the scripts I am using:

Code: Select all

<#h:: 
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden 
If HiddenFiles_Status = 2  
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1 
Else  
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2 
WinGetClass, eh_Class,A 
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA") 
send, {F5} 
Else PostMessage, 0x111, 28931,,, A 
Return
and:

Code: Select all

<#y::
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt
If HiddenFiles_Status = 1 
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 0
Else 
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 1
WinGetClass, eh_Class,A
If (eh_Class = “#32770” OR A_OSVersion = “WIN_VISTA”)
send, {F5}
Else PostMessage, 0x111, 28931,,, A
Return
Is there any way to get file explorer to automatically refresh, even whilst I am not on the screen (e.g. lets say I am on file explorer, toggle the files, and the screen automatically refreshes - but when I go on, say, google chrome, and toggle the hidden files, I don't want the chrome screen to refresh) - I think using send F5 would accomplish the first bit (refreshing whilst I am on the file explorer screen), but it would refresh chrome if I were on the google chrome screen.
Any help is appreciated!
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Refreshing the file explorer

04 Jan 2016, 11:31

This function may do the trick for ya.

Code: Select all

refreshExplorer()
{
	for wb in ComObjCreate("Shell.Application").Windows
	{
		if wb.Name = "Windows Explorer"
			ControlSend, ToolbarWindow323, {F5}, % "ahk_id " wb.hwnd
	}
	Return
}
manosathya98
Posts: 4
Joined: 04 Jan 2016, 08:56

Re: Refreshing the file explorer

04 Jan 2016, 12:02

Thank you! It didn't work at first, so just changed windows explorer to file explorer and now it works brilliantly :)
manosathya98
Posts: 4
Joined: 04 Jan 2016, 08:56

Re: Refreshing the file explorer

04 Jan 2016, 12:13

One more thing actually, everything works as it is, but is it possible to do the above whilst file explorer is closed completely? (at the moment it only works when on the screen or minimised)
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Refreshing the file explorer

04 Jan 2016, 12:24

I guess I don't see why it would be necessary if explorer.exe isn't open as a window. I would think it should display correctly if you open it after using your hotkey to update the registry.
manosathya98
Posts: 4
Joined: 04 Jan 2016, 08:56

Re: Refreshing the file explorer

04 Jan 2016, 14:30

It doesn't work as it is if the file explorer is closed, but it's not really a necessity, just wanted to see if it could be done haha
shajeeh

Re: Refreshing the file explorer

11 Jan 2017, 23:06

I am also having the same problem of refreshing the explorer, i used the above combination on my windows 10 as
[;------------------------------------------------------------------------
; Show hidden folders and files in Windows XP
;------------------------------------------------------------------------
; User Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
; Value Name: Hidden
; Data Type: REG_DWORD (DWORD Value)
; Value Data: (1 = show hidden, 2 = do not show)

#z::

RegRead, ShowHidden_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden
if ShowHidden_Status = 2
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
Else
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
WinGetClass, CabinetWClass
PostMessage, 0x111, 28931,,, A
refreshExplorer()
{
for wb in ComObjCreate("Shell.Application").Windows
{
if wb.Name = "Windows Explorer"
ControlSend, ToolbarWindow323, {F5}, % "ahk_id " wb.hwnd
}
}
Return
]
but is not refreshing and i have to refresh manually
i also tried writing "File Explorer" instead of "Windows Explorer" but that did not help as well
can someone please identify the mistake
Noesis
Posts: 301
Joined: 26 Apr 2014, 07:57

Re: Refreshing the file explorer

12 Jan 2017, 01:17

You're never actually calling the refreshExplorer() function you've only got it being defined. You need a line saying refreshExplorer() within the hotkey (there is an implied return between PostMessage and the current refreshExplorer() function definition). In other words, Function definitions aren't auto-executed.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Refreshing the file explorer

12 Jan 2017, 02:12

I used this to toggle hide/show extensions on Windows XP:

Code: Select all

;toggle hide/show extensions (Windows XP)
RegRead, vIsHidden, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt
if (vIsHidden = 1) ;(0=show/1=hide)
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 0
else
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 1

DetectHiddenWindows, On

SendMessage, 0x111, 28931,,, ahk_class Progman

WinGet, vWinList, List, ahk_class CabinetWClass
Loop, %vWinList%
SendMessage, 0x111, 28931,,, % "ahk_id " vWinList%A_Index%

WinGet, vWinList, List, ahk_class ExploreWClass
Loop, %vWinList%
SendMessage, 0x111, 28931,,, % "ahk_id " vWinList%A_Index%

if (vIsHidden = 1)
MsgBox % "extensions now shown"
else
MsgBox % "extensions now hidden"
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Refreshing the file explorer

12 Jan 2017, 06:20

You might want to try this (on your own risk). It doesn't need a refresh here:

Code: Select all

#NoEnv
; SHGetSetSettings   -> msdn.microsoft.com/en-us/library/bb762200(v=vs.85).aspx
; SHELLSTATE         -> msdn.microsoft.com/en-us/library/bb759788(v=vs.85).aspx
; SSF Constants      -> msdn.microsoft.com/en-us/library/bb762591(v=vs.85).aspx
; SSF_SHOWALLOBJECTS = 0x00000001
; SSF_SHOWEXTENSIONS = 0x00000002
; Get the current settings
VarSetCapacity(OrgState, 36, 0)
DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &OrgState, "UInt", 0xFFFFFFFF, "Int", 0)
VarSetCapacity(SetState, 36, 0)
Return
; ----------------------------------------------------------------------------------------------------------------------------------
^+h:: ; hide hidden files and extensions
NumPut(0, SetState, "UInt")
Mask := 0x03
DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &SetState, "UInt", Mask, "Int", 1)
Return
; ----------------------------------------------------------------------------------------------------------------------------------
^+s:: ; show hidden files and extensions
NumPut(0x03, SetState, "UInt")
Mask := 0x03
DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &SetState, "UInt", Mask, "Int", 1)
Return
; ----------------------------------------------------------------------------------------------------------------------------------
^+r:: ; restore the original settings
DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &OrgState, "UInt", 0xFFFFFFFF, "Int", 1)
Return
Harry
Posts: 4
Joined: 14 Feb 2017, 01:48

Re: Refreshing the file explorer

14 Feb 2017, 02:08

I like the dll call method a lot. It took me a while to sort through it though, but it doesn't brute force the registry or rely on refresh codes.

For my purposes, I only want to control hidden files and I wanted to use the same key to toggle them on and off. Here's what I've come up with, based on the "just me" code...

Code: Select all

#NoEnv
NumpadDiv::
	VarSetCapacity(StatePtr, 36, 0)
	DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &StatePtr, "UInt", 1, "Int", 0)
	StateVal := NumGet(StatePtr, "UInt")
	If StateVal = 0
		NumPut(1, StatePtr, "UInt")
	Else
		NumPut(0, StatePtr, "UInt")
	DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &StatePtr, "UInt", 1, "Int", 1)
Return
or fully commented...

Code: Select all

#NoEnv
;
; This script toggles the visibility of items marked as hidden in the file explorer.
;
; Specify a key for the toggle function.
; For me, it's the numberpad slash key.
NumpadDiv::
;
; Create a memory structure that will hold the visibility state data.
; We'll be dealing with Dll system calls, so it should be 36 bytes, filled with 0s.
	VarSetCapacity(StatePtr, 36, 0)
;
; Call the system shell SHGetSetSettings function.
; Read the current state data into our StatePtr structure.
; Mask for the last byte. This holds the fShowAllObjects member (visibility state)
; The final 0 parameter makes sure we READ the value. We don't want to write over it yet.
	DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &StatePtr, "UInt", 1, "Int", 0)
; 
; StatePtr is a pointer, so put its data into a more friendly variable.
	StateVal := NumGet(StatePtr, "UInt")
;
; Check the value. If hidden files are actually visible (0), change StatePtr content to hide them (1)
; Otherwise hidden files are indeed hidden (1), change StatePtr content to visible (0) 
	If StateVal = 0
		NumPut(1, StatePtr, "UInt")
	Else
		NumPut(0, StatePtr, "UInt")
;
; Call the system shell function again.
; The final 1 parameter writes the newly toggled value up to the system settings.
	DllCall("Shell32.dll\SHGetSetSettings", "Ptr", &StatePtr, "UInt", 1, "Int", 1)
;
Return
I also like the disclaimer. So yes, use at your own risk.

--Regards
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Refreshing the file explorer

15 Feb 2017, 08:27

@just me
Thanks so much for this.
Btw it didn't appear to refresh Desktop/folder windows for me (on Windows 7),
so I added this line at the end:
DllCall("Shell32\SHChangeNotify", Int,0x8000000, UInt,0, Ptr,0, Ptr,0)
The code below only toggles hide/show extensions:

Code: Select all

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

if (vState = 0)
NumPut(vNum, SHELLSTATE, "UInt")
else
NumPut(0, SHELLSTATE, "UInt")
DllCall("Shell32.dll\SHGetSetSettings", Ptr,&SHELLSTATE, UInt,vNum, Int,1)

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

;refresh Desktop/folder windows
DetectHiddenWindows, On
GroupAdd, vGroupFolder, ahk_class CabinetWClass
GroupAdd, vGroupFolder, ahk_class ExploreWClass
PostMessage, 0x111, 28931, , SHELLDLL_DefView1, ahk_class Progman
WinGet, vWinList, List, ahk_group vGroupFolder
Loop, %vWinList%
PostMessage, 0x111, 41504, , ShellTabWindowClass1, % "ahk_id " vWinList%A_Index%
;PostMessage, 0x111, 28931, , SHELLDLL_DefView1, % "ahk_id " vWinList%A_Index% ;also works
Return
[EDIT:]
When I tested,
SHChangeNotify did not work on show/hide hidden files by itself,
even with SHCNE_ALLEVENTS := 0x7FFFFFFF.
Although F5 refresh did.
So I added an alternative way to refresh Desktop/folder windows (tested on Windows 7).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Harry
Posts: 4
Joined: 14 Feb 2017, 01:48

Re: Refreshing the file explorer

18 Feb 2017, 23:36

Yeah, I'm running Win 10, so there are bound to be differences.

To test the desktop hide/show capability on my system, I created a folder on the desktop and gave it a "!" warning triangle icon. I then set as hidden. Now, it pops up or disappears to give me a visual reminder of the current state of visibility. I see there are methods for putting an indicator on the system tray, but maybe that's a project for later.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder, sanmaodo and 138 guests