Skip to content

Instantly share code, notes, and snippets.

@sionta
Last active September 20, 2022 12:57
Show Gist options
  • Save sionta/e7eb18b1ea4940a4d49467d980300cd2 to your computer and use it in GitHub Desktop.
Save sionta/e7eb18b1ea4940a4d49467d980300cd2 to your computer and use it in GitHub Desktop.
Windows10: Add folder or drive to navigation pane explorer.exe
:: TASKER:
:: - support disable/enable default navigation pane
:: i.e Quick Access, OneDrive, This PC, Network, etc.
:: - support relative path directory or icon file i.e cmd.exe
::
@echo off
if "%~1"=="" (
:help
echo;
echo usage: %~n0 [create ^| delete ^<name^>] [options]...
echo;
echo name specify navigation pane name.
echo create create a new navigation pane.
echo delete delete already created.
echo;
echo options:
echo /q quiet mode ^(re-create again^)
echo /d directory path ^(default current directory^)
echo /i icon file full path ^(.ico, .exe^)
rem echo /i icon file path ^(support .ico, .exe, .dll^)
exit /b
) else if "%~1"=="/?" (
call :help
echo;
echo example:
echo;
echo %~n0 create foo /i %windir%\System32\cmd.exe
rem echo;
rem echo %~n0 create foo /d "c:\bar baz" /i imageres.dll=5359
echo;
echo %~n0 create foo /d "c:\bar baz" /i "c:\bar baz\foo.ico"
echo;
echo %~n0 delete foo
exit /b
)
setlocal
set force=0
set create=0
set delete=0
:parse
if "%~1"=="" (
goto :begin
) else if /i "%~1"=="create" (
if "%~2"=="" (
echo name must be specified.
goto :omega
)
set "create=%~1"
set "NAMEDIR=%~2"
shift /1
) else if /i "%~1"=="delete" (
if "%~2"=="" (
echo name must be specified.
goto :omega
)
set "delete=1"
set "NAMEDIR=%~2"
shift /1
) else if /i "%~1"=="info" (
if not exist "*.txt" (
echo nothing!
) else for /f "tokens=*" %%i in (
'where "%~dp0data:*.txt" 2^>nul'
) do if not "%%i"=="" (
echo;& type "%%i"
)
goto :omega
) else if /i "%~1"=="/d" (
if "%~2"=="" (
echo directory path must be specified.
goto :omega
)
set "DESTDIR=%~2"
shift /1
) else if /i "%~1"=="/i" (
if "%~2"=="" (
echo icon file must be specified.
goto :omega
)
set "ICONDIR=%~2"
shift /1
) else if /i "%~1"=="/q" (
set "force=1"
) else (
echo %~n0: '%1' invalid command. try '%~n0 /?' for usage.
goto :omega
)
shift /1
goto :parse
:begin
set "cwd=%~dp0"
set "cwd=%cwd:~0,-1%"
if not exist "%cwd%\data" (
mkdir "%cwd%\data" >nul
echo DON'T DELETE ANY FILES ON THIS DIRECTORY
echo %cwd%\data
)>"%cwd%\data\KEEPME"
if not defined NAMEDIR (
echo error: name not specified.
goto :omega
)
set "NAMEDIR=%NAMEDIR:\=-%"
rem set "filedat=%cwd%\data\%NAMEDIR%.dat"
rem set "filetxt=%cwd%\data\%NAMEDIR%.txt"
rem set "filecmd=%cwd%\data\%NAMEDIR%.cmd"
if %create%==1 (
goto :create_item
) else if %delete%==1 (
goto :delete_item
) else (
echo error: the specified command was not found.
echo type '%~n0 /?' for usage and example.
)
:omega
endlocal
exit /b
:create_item
if "%force%"=="1" (
call "%cwd%\data\%NAMEDIR%.cmd" 2>nul
) else if exist "%cwd%\data\%NAMEDIR%.txt" (
echo the name '%NAMEDIR%' already exist.
echo;
echo information of '%NAMEDIR%':
type "%cwd%\data\%NAMEDIR%.txt"
goto :omega
)
rem check directory
if not defined DESTDIR (
set "DESTDIR=%CD%"
rem echo error: directory path not specified.
rem goto :omega
)
rem remove traling \
if "%DESTDIR:~-1%" =="\" set "DESTDIR=%DESTDIR:~0,-1%"
if not exist "%DESTDIR%\" (
echo error: directory '%DESTDIR%' not found.
goto :omega
)
if not defined ICONDIR set ICONDIR=%windir%\system32\imageres.dll,3
if not exist "%temp%\guid.bat" (
echo @if ^(@X^)==^(@Y^) @end /*
echo @cscript //E:JScript //nologo "%%~f0" %%*
echo @exit /b %%errorlevel%%
echo @*/WScript.Echo^(^(new ActiveXObject^("Scriptlet.TypeLib"^)^).Guid^)
)>"%temp%\guid.bat"
call "%temp%\guid.bat">"%cwd%\data\%NAMEDIR%.dat"
set /p "NEWGUID="<"%cwd%\data\%NAMEDIR%.dat"
(@rem file info
echo name: %NAMEDIR%
echo path: %DESTDIR%
echo icon: %ICONDIR%
echo uuid: %NEWGUID%
)>"%cwd%\data\%NAMEDIR%.txt"
set /p <nul="Creating %NAMEDIR% ."
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" /ve /t REG_SZ /d "%NAMEDIR%" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" /v "Author" /t REG_SZ /d "anatt. (@sionta)" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" /v "InfoDir" /t REG_SZ /d "%DESTDIR%" /f
if not defined SORTDIR set SORTDIR=0
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" /v "SortOrderIndex" /t REG_DWORD /d "%SORTDIR%" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" /v "System.IsPinnedtoNameSpaceTree" /t REG_DWORD /d "1" /f
rem subkey DefaultIcon
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\DefaultIcon" /ve /t REG_SZ /d "%ICONDIR%" /f
rem subkey InProcServer32
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\InProcServer32" /ve /t REG_SZ /d "shdocvw.dll" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\InProcServer32" /v "ThreadingModel" /t REG_SZ /d "Both" /f
rem subkey Instance
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\Instance" /v "CLSID" /t REG_SZ /d "{0afaced1-e828-11d1-9187-b532f1e9575d}" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\Instance\InitPropertyBag" /v "Attributes" /t REG_DWORD /d "21" /f
@rem >nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\Instance\InitPropertyBag" /v "Target" /t REG_SZ /d "%DESTDIR%" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\Instance\InitPropertyBag" /v "Target" /t REG_EXPAND_SZ /d "%DESTDIR%" /f
rem subkey ShellEx
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellEx\PropertySheetHandlers\tab 1 general" /ve /t REG_SZ /d "{21b22460-3aea-1069-a2dc-08002b30309d}" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellEx\PropertySheetHandlers\tab 2 customize" /ve /t REG_SZ /d "{ef43ecfe-2ab9-4632-bf21-58909dd177f0}" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellEx\PropertySheetHandlers\tab 3 sharing" /ve /t REG_SZ /d "{f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellEx\PropertySheetHandlers\tab 4 security" /ve /t REG_SZ /d "{1f2e5c40-9550-11ce-99d2-00aa006e086c}" /f
rem subkey ShellFolder
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellFolder" /v "Attributes" /t REG_DWORD /d "4034920525" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellFolder" /v "HideAsDeletePerUser" /t REG_SZ /d "" /f
>nul reg add "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%\ShellFolder" /v "WantsFORPARSING" /t REG_SZ /d "" /f
set /p <nul="."
:: navigation pane
>nul reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\%NEWGUID%" /ve /t REG_SZ /d "%NAMEDIR%" /f
set /p <nul="."
:: hide folder navigation pane from desktop
>nul reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v "%NEWGUID%" /t REG_DWORD /d "1" /f
rem export for uninstall
rem reg export /y "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" "%cwd%\data\%NAMEDIR%_CLSID.reg"
rem reg export /y "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\%NEWGUID%" "%cwd%\data\%NAMEDIR%_NAMESPACE.reg"
rem reg export /y "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" "%cwd%\data\%NAMEDIR%_NEWSTARTPANEL.reg"
(@echo @echo off
@echo ^>^nul 2^>^&1 reg delete "HKCU\SOFTWARE\Classes\CLSID\%NEWGUID%" /f
@echo ^>^nul 2^>^&1 reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\%NEWGUID%" /f
@echo ^>^nul 2^>^&1 reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v "%NEWGUID%" /f
@echo del /f /q "%cwd%\data\%NAMEDIR%.*" ^&^& exit /b %%errorlevel%%
)>"%cwd%\data\%NAMEDIR%.cmd"
echo; done.
goto :omega
:delete_item
if not exist "%cwd%\data\%NAMEDIR%.dat" (
if exist "%cwd%\data\%NAMEDIR%.cmd" (
call "%cwd%\data\%NAMEDIR%.cmd"
goto :omega
)
echo error: '%NAMEDIR%' not created.
goto :omega
)
set /p <nul="Removing %NAMEDIR% ."
:: remove registry by uuid
set /p "OLDGUID="<"%cwd%\data\%NAMEDIR%.dat"
>nul reg query "HKCU\SOFTWARE\Classes\CLSID\%OLDGUID%" && ^
>nul reg delete "HKCU\SOFTWARE\Classes\CLSID\%OLDGUID%" /f
set /p <nul="."
>nul reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\%OLDGUID%" && ^
>nul reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\%OLDGUID%" /f
set /p <nul="."
>nul reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /f "%OLDGUID%" && ^
>nul reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v "%OLDGUID%" /f
:: cleanup
del /f /q "%cwd%\data\%NAMEDIR%.*" | echo; done.
goto :omega
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment