Enable Recycle Bin on mapped network drives

A few years ago I discovered how redirected user profile folders in Windows get Recycle Bin protection, even when the folders are redirected to a network location. This was a huge find for me, and I used this feature to add Recycle Bin coverage to some of my mapped network drives. I shared this information on another forum here:

http://forums.mydigitallife.info/threads/16974-Tip-Network-Recycle-bin

Today I figured out a better way to achieve the same goal that doesn't rely on user profile folder redirection, and am sharing that information for other users to try out. You might want to take a look at these forum topics for additional information:

The standard disclaimer applies - this might break stuff. I've only tested in Windows 8, and my testing is limited. Try this at your own risk.

This is what I've learned (or think I've learned - I might be wrong):

  • Windows Vista and later store the configuration settings for the Recycle Bin for redirected user profile folders in this registry key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder
  • Under this key are separate keys for each redirected folder that is protected by the Recycle Bin. The keys contain the configuration information for each protected folder, and are named to match the GUIDs for "Known Folders." A list of the Known Folder to GUID mappings is available in one of the links above.
  • The registry also contains a list of "known folders" at this location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions

So, I reasoned that if I could create my own custom "known folder," I could add that to the list of folders that were protected by the Recycle Bin and protect any mapped network drive I wanted. So I looked at the list of existing "known folders" and created a key that was similar to the Documents key. I then fiddled with the values in the key until I narrowed it down to the minimum number needed to make the recycle bin work.

This .reg file will protect a mapped X: drive with a ~50GB recycle bin. You should modify the file to fit your needs:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{9147E464-33A6-48E2-A3C9-361EFD417DEF}]
"RelativePath"="X:\\"
"Category"=dword:00000004
"Name"="XDrive"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{9147E464-33A6-48E2-A3C9-361EFD417DEF}]
"MaxCapacity"=dword:0000c7eb
"NukeOnDelete"=dword:00000000

A few things of note:

  • The GUID in the above .reg file {9147E464-33A6-48E2-A3C9-361EFD417DEF} came from this PowerShell command: "{"+[guid]::NewGUID().ToString().ToUpper()+"}"
  • Each "known folder"/Recycle Bin combination requires a unique GUID. If you don't want to use PowerShell to generate a GUID, you can use an online GUID generator.
  • I don't know what the "Category" value does, but the key I copied had it set to 4, and that works, so I didn't test any other values.
  • The "Name" value is required, but is not the name that will be shown if you right-click on the Recycle Bin and select properties. (At least not in my environment.) In my environment, the name that is shown is the name of the network drive.
  • Making this change adds a "Location" tab to the properties page of your mapped network drives. I suspect this could be removed by changing the "Category" value, but didn't bother to find out.
  • I only tested with mapped network drives. I suspect this would work with UNC paths as well, but I didn't bother testing.

I hope you're as excited to find this as I was to figure it out. Let me know if this works for you. I now plan to deploy the registry keys with Group Policy Preferences and will update this forum post with any information I discover.

Best regards

--Russel

Update: I am now using Group Policy Preferences to deploy the needed registry keys, and all my mapped network drives are now protected by the recycle bin.

Update 2: I have tested now with UNC paths, and this works fine. I still use mapped network drives, but if your environment requires UNC paths instead, you can use them. Note however that if you have a mapped network drive that points to a UNC path, and you protect the UNC path with a registry change, if a user deletes a file from the mapped network drive that points to that UNC path, the file will be permanently deleted. See below for more details.


October 3rd, 2013 9:27am

This is what I do as a domain policy.

On the DC I already have various logon batch files set up in the User Configuration\policies\Windows settings\Scripts which typically have things like

net use r: \\hv1\company_docs

Rather than scattering new policies around, I've simply added to this batch file, for this drive:

rem add company_docs to local recycle bin
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{BB6CC368-07C4-4EF1-B600-6BBF588505A6}  /f
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{BB6CC368-07C4-4EF1-B600-6BBF588505A6} /v RelativePath /t REG_SZ /d R:\  /f
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{BB6CC368-07C4-4EF1-B600-6BBF588505A6} /v Category /t REG_DWORD /d 00000004  /f
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{BB6CC368-07C4-4EF1-B600-6BBF588505A6} /v Name /t REG_SZ /d RDrive  /f

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{BB6CC368-07C4-4EF1-B600-6BBF588505A6} /f
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{BB6CC368-07C4-4EF1-B600-6BBF588505A6} /v MaxCapacity /t REG_DWORD /d 0000c7eb /f
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{BB6CC368-07C4-4EF1-B600-6BBF588505A6} /v NukeOnDelete /t REG_DWORD /d 00000000 /f

This seems to work perfectly (on Win 7 clients), so thankyou for a brilliant solution.

One minor thing: Since I haven't created an equivalent logoff script to remove these registry entries, what I don't know is what happens on logins after the first one.  There doesn't seem to be any unexpected effects, I suppose reg add just fails silently if the keys already exist.

Richard




  • Edited by richardmh Thursday, May 29, 2014 10:27 AM
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2014 12:27pm

Thank you for your reply Russel, I didnt mention this in the previous post, but we did try creating the Recycle Bins at the network user-folder path instead of the root.  See the 2 examples below for the results.

Example 1: Network Recycle Bins
\\server\share\user\documents (from folder redirection)

\\server\share (manually created)

-      IIn this case (as mentioned in the previous post), everyone ends up having a shared Recycle Bin, so everyone sees all of the files other people have deleted in their own conglomerated view when they look in their Recycle Bin.  This leads to a very busy and full Recycle Bin and end users raising questions why files they didnt delete show up in their Recycle Bin.

Example 2: Network Recycle Bins

\\server\share\user\documents (from folder redirection)

\\server\share\user (manually created)

-      IIn this case, users do end up with their own conglomerated view in their Recycle Bin (i.e., no more seeing all the files other people have deleted), BUT there are 2 negatives to this configuration:

  • Only files within the folder \\server\share\user are protected with Recycle Bin, so other common folders in the root of the share arent protected via Recycle Bin.
  • And when files are deleted from \\server\share\user\documents, because they are protected twice by the Recycle Bin (once from folder redirection and once from the manually created Recycle Bin at the user-folder level), 2 copies of the deleted files appear in the conglomerated view of the Recycle Bin.  This lead to users asking why they had duplicate files showing up for the majority of files they deleted.  They often got confused thinking there were different versions of the files instead of duplicates.

December 23rd, 2014 7:01pm

I am also getting an access error, on computers not using offline files. What is the best way to undo the registry entries (too much time has passed to restore the registry) ?

Thanks.


  • Edited by crewlaw Wednesday, February 18, 2015 3:49 AM
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 6:23am

I am also getting an access error, on computers not using offline files. What is the best way to undo the registry entries (too much time has passed to restore the registry) ?

Thanks.


I dont have any information about your access error. But removing the registry entries can be done by adding a - in front of the key name in a .reg file. Note that if you followed the steps above to create these registry settings, there are 2 parts, one that is applied to the Computer side (required Administrative credentials) and the other which is done on the User side (per user).  Here are examples using the - sign in a registry file to remove/clean up the GUIS keys you created.

Computer / Administrative side:

Windows Registry Editor Version 5.00

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{<your GUID>}]

User side:

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{<your GUID>}]


February 18th, 2015 10:58am

FANTASTIC work Russel !
This is extremely helpful.

I've turned your work into a Bat Script that will automatically make the reg file.
It creates a unique guid each time it is run, so no worries on overlaps.

Just copy and paste the following into notepad
and save it as "Network Recycling Bin - auto make registry file.bat"

echo off
REM ========== MAIN FUNCTION  ========================
 
Call :CreateREGfile
PAUSE
goto :eof
 
 
 
 
REM ========== SUB FUNCTIONS  ========================
 
:CreateREGfile
set /p RelativePath=Enter current mapped path of drive (e.g. X:\FileShare\D_Drive):
REM replace \ with \\ (for reg value its a requirement)
Set RelativePath=%RelativePath:\=\\% 
 
 
set /p MaxBinSize_Dec=Enter max size (in mb) (eg 11gb=11000):
call :toHex %MaxBinSize_Dec% MaxBinSize_Hex
 
 
Set outputREG="Network Recycling Bin - %RelativePath:~0,1% Drive (%MaxBinSize_Dec%mb).reg"
 
 
call :MakeGUID_VBS NewGUID
REM echo My new GUID : %NewGUID%
 
 
echo Windows Registry Editor Version 5.00 > %outputREG%
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\%NewGUID%] >> %outputREG%
echo "RelativePath"="%RelativePath%" >> %outputREG%
echo "Category"=dword:00000004 >> %outputREG%
echo "Name"="NetworkDrive2RecyclingBin_%NewGUID:~1,5%" >> %outputREG%
      REM The "Name" value is required, but is not the name that will be shown if you right-click on the Recycle Bin and select properties. That will be autoset to the network drive name.
echo.>> %outputREG%
echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\%NewGUID%>> %outputREG%
echo "MaxCapacity"=dword:%MaxBinSize_Hex% >> %outputREG%
echo "NukeOnDelete"=dword:00000000 >> %outputREG%
goto :eof
 
 
 
:MakeGUID_VBS
echo set obj = CreateObject("Scriptlet.TypeLib") > TEMP_generateGUID.vbs
echo WScript.Echo obj.GUID >> TEMP_generateGUID.vbs
FOR /F "usebackq tokens=*" %%rin (`CSCRIPT "TEMP_generateGUID.vbs"`)DO SET RESULT=%%r
set %1=%RESULT%
 
del TEMP_generateGUID.vbs
goto :eof
 
 
:toDec
:: todec hex dec -- convert a hexadecimal number to decimal
::             -- hex [in]      - hexadecimal number to convert
::             -- dec [out,opt] - variable to store the converted decimal number in
SETLOCAL
set /a dec=0x%~1
( ENDLOCAL & REM RETURN VALUES
    IF "%~2" NEQ "" (SET %~2=%dec%)ELSE ECHO.%dec%
)
EXIT /b
 
 
:toHex
:: eg  call :toHex dec hex -- convert a decimal number to hexadecimal, i.e. -20 to FFFFFFEC or 26 to 0000001A
::             -- dec [in]      - decimal number to convert
::             -- hex [out,opt] - variable to store the converted hexadecimal number in
::Thanks to 'dbenham' dostips forum users who inspired to improve this function
:$created 20091203 :$changed 20110330 :$categories Arithmetic,Encoding
:$source http://www.dostips.com
SETLOCAL ENABLEDELAYEDEXPANSION
set /a dec=%~1
set "hex="
set "map=0123456789ABCDEF"
for /L %%Nin (1,1,8)do (
    set /a "d=dec&15,dec>>=4"
    for %%Din (!d!)do set "hex=!map:~%%D,1!!hex!"
)
rem !!!! REMOVE LEADING ZEROS by activating the next line, e.g. will return 1A instead of 0000001A
rem for /f "tokens=* delims=0" %%A in ("%hex%") do set "hex=%%A"&if not defined hex set "hex=0"
( ENDLOCAL & REM RETURN VALUES
    IF "%~2" NEQ "" (SET %~2=%hex%)ELSE ECHO.%hex%
)
EXIT /b
 
 
:eof
  • Edited by WillTurner Monday, April 06, 2015 9:43 AM formatting
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2015 9:31am

Just wanted to say, "Great work!" Using this .reg on my Windows 7 machine at work and it's a big relief to have the Recycle Bin on my network drive since I like to do all my current work directly on it.
April 30th, 2015 2:42pm

First of all thank you for sharing your knowledge!

But ... I have exactly the same issue. When deleting a file Windows first asks whether I want to move it to the recycle bin, then it tells me in another dialog I need permission (granted by administrator) and shows a retry button. Then clicking retry fails as the file is already deleted. It does not matter whether Explorer runs as administrator anyways as the behavior is the same.

I assume that this is related to that the remote sharing the drive is on a Linux machine and not NTFS at all - as you were pointing out you never tried that - or did you actualy try that in the meantime?

Also the workaround provided by ColoradoState did not do the trick.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 9:03pm

I'm pretty sure you've got an issue with the permissions on your file share. I don't run Linux file servers and probably won't ever, so I don't think I'll be able to find a solution. Keep in mind that you need write permission at the share level as well at the file system level.

--Russel

May 23rd, 2015 12:43pm

Thanks for your reply.

That indeed sounds like a permission issue - but the permissions to write and delete are obviously there as I am able to create and delete files without any problem - but maybe I am missing something here. I have as well tried that with a shared NTFS host drive (though still mapped through VirtualBox on a Linux host) with the same result.

I have created a more broadly formulated question at Stack Exchange covering this issue some days ago - if you would like to follow check:

http://superuser.com/questions/917384/virtual-boxes-linux-hosts-windows-guests-shared-folders-and-recycle-bins

Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2015 1:32pm

Dear,

I give this error: %Nin was unexpected at this time.

Batch file is not worked on win 8 and 8.1

What is wrong?

Regards

June 27th, 2015 7:39am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics