I decided to take the keys and commands that Ben supplied and write a single batch file that toggles both the Hidden
and ShowSuperHidden
values on or off together.
Toggling Hidden/Super-Hidden Files with a Batch File
You can download ToggleHidden.bat here, but if you'd prefer to copy the script into a .bat
or .cmd
file yourself, here's the source code:
@echo off
REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "Hidden" | Find "0x0"
If %ERRORLEVEL% == 0 goto show
IF %ERRORLEVEL% == 1 goto hide
goto :error
:show
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /f /d 1 > NUL
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /f /d 1
goto restart
:hide
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /f /d 0 > NUl
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /f /d 0
goto restart
:error
echo There was an error! Check the script.
pause
goto :eof
:restart
taskkill /f /im explorer.exe
start explorer
A breakdown of what the script does: it queries the data of the Hidden
value; if it's off, it toggles both it and ShowSuperHidden
on. If it's already on, it toggles both it and ShowSuperHidden
off. I decided to design the script in this way because it's rare that I personally need to see hidden files without also seeing system files, but you can change this behaviour if you prefer.1
After either enabling or disabling these registry values, the script then kills and restarts the Windows Explorer explorer process. If, for some reason, the value of Hidden
can't be determined by the query
command then the script breaks and echoes an error before exiting.
Mapping the Batch File to a Hotkey
To satisfy my criteria for maximum convenience, I placed the newly-created ToggleHidden.bat
file somewhere on my computer and used AutoHotKey to map a hotkey combination to run it. I did this by adding the following to my existing AHK script:
Ctrl & H::
Run PATH\TO\FILE
Return
I used AutoHotKey here because I already use it for similar purposes and find it the more useful method of assigning hotkeys to run my programs, but if you'd rather not have to install AHK for the purpose of this step, you can also use this native Windows method for assigning hotkeys to a program.
I can now use the hotkey combination Ctrl+H to hide and quickly show or hide hidden/system files at my convenience... and it works beautifully, if I do say so myself.
1 If you do plan to go down this route, it's worth noting that, in the Windows ecosystem, superhidden files/folders act as a subset of hidden files/folders.
What this means when it concerns these two registry values is that you can enable the Hidden
value without enabling ShowSuperHidden
, but you can't enable ShowSuperHidden
without enabling Hidden
; doing so will show you only normal items, because Windows considers superhidden items a type of hidden item, and if hidden items are hidden, so are superhidden items. To put it simply: if you're planning to turn on ShowSuperHidden
, you need to make sure you turn on Hidden
with it.
1Its easier to use taskkill to kill explorer. Especially since powershell is not natively part of windows 7. – LPChip – 2017-08-12T21:53:02.893
Great find on the registry key. Powershell is available natively in Windows 7 onwards, but I agree it would make more sense to stick to CMD when we're already using it. I suppose it's a matter of personal preference. Thanks for the key, Ben. – Hashim – 2017-08-12T23:17:53.683