Refreshing the file explorer

Get help with using AutoHotkey 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] [Download] GeSHi © Codebox Plus

<#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] [Expand] [Download] GeSHi © Codebox Plus



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: 359
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] [Download] GeSHi © Codebox Plus

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: 359
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: 93
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: 738
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] [Expand] [Download] GeSHi © Codebox Plus

just me
Posts: 4154
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] [Expand] [Download] GeSHi © Codebox Plus

Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
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] [Download] (Untitled.ahk)GeSHi © Codebox Plus

#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] [Expand] [Download] (ToggleHidden.ahk)GeSHi © Codebox Plus



I also like the disclaimer. So yes, use at your own risk.

--Regards
User avatar
jeeswg
Posts: 738
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] [Expand] [Download] GeSHi © Codebox Plus



[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).
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”

Who is online

Users browsing this forum: Demonkil, orlinowns, Ovg, Pokypok, shawnwmorris, Solid_Pliskin, Yahoo [Bot] and 32 guests