Pages

16 February 2021

Open Windows Explorer collapsed

 Anoying.

When opening Windows Explorer it opens with all folders collapsed. The behaviour can come from different settings, such as:

Showing all folders
Allowing network discovery
Last opened folder saved when closing the explorer

And probably a few I don't k now about.

Some dude (EpilepticUnderscore) over at social.technet.com created a batch file to overcome this annoyance.
See the original thread here: Collapse all folder-trees when closing Explorer (microsoft.com)

The batch job way:

<batchscript start>
@ECHO OFF
:cmdstart

ECHO.
ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ECHO ~ Windows 7 Batchscript to avoid expanded directories ~
ECHO ~ in the Nav-Pane after closing Windows Explorer. ~
ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::Created by Mathrius/MK90 - Regards to Daniel M. from the TechNet-Forums / 29.04.2011
::TN-Thread:social.technet.microsoft.com/Forums/en-US/w7itproui/thread/48ebc898-290d-405f-b4d5-c3dc72278b76
ECHO.
ECHO Select an option and press enter:
ECHO.
ECHO [1] Set the new initial (fixed) expanded folders view
ECHO [2] Set the expanded folders view back to default behavior
ECHO [3] Open Explorer window
ECHO [4] Exit Batchscript
ECHO.
set /p choice=
ECHO.
if "%choice%" == "1" goto fixnavpane
if "%choice%" == "2" goto navpanedef
if "%choice%" == "3" goto openexplorer
if "%choice%" == "4" goto exitcmd
ECHO Invalid option, please try again.
pause
cls
goto cmdstart

:fixnavpane
(ECHO HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane [1 5 17])>"%TEMP%\reginicmd"
regini "%TEMP%\reginicmd"
ECHO.
ECHO Expand/Collapse the folders of the Explorer Navigation Pane and close its window.
ECHO (Only the folder-tree state of the 'desktop-subfolders' will be saved.)
::Or use "regedit /s regfile" or "REG ADD" to set the wanted "ExpandedState" data
ECHO.
pause
(ECHO HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane [2 6 19])>"%TEMP%\reginicmd"
regini "%TEMP%\reginicmd"
ECHO.
ECHO The permissions for the registry-key
ECHO HKCU\...\Explorer\Modules\NavPane
ECHO are now set to Read-Only.
ECHO (New expanded folders view was set.)
ECHO.
pause
del "%TEMP%\reginicmd"
cls
::goto cmdstart
exit

:navpanedef
(ECHO HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane [1 5 17]
ECHO HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane
ECHO ;TestExampleValue = DELETE
ECHO ;TestExampleValue = REG_BINARY 8 9 17)>"%TEMP%\reginicmd"
regini "%TEMP%\reginicmd"
ECHO.
ECHO The Nav-Pane expanded folders behavior was restored.
ECHO.
pause
del "%TEMP%\reginicmd"
cls
::goto cmdstart
exit
:openexplorer
explorer /e,
cls
goto cmdstart
:exitcmd
exit
<batchscript end>
 
The PowerShell way:
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane -Name ExpandedState -ErrorAction SilentlyContinue            
Start-Process -FilePath $env:windir\explorer.exe
Use that to launch Explorer each time.

No comments:

Post a Comment