5

Quick summary: I am a tinkerer and I hate to click through the GUI, I don't need $Recycle.Bin so I want to disable it by using Set-ItemProperty to modify registry.

As in title, I want to use regedit.exe (I know reg add and stuff but I don't use reg, instead I use Set-ItemProperty and its cohorts to do the work and I would like to put all commands in one file) and gpedit.msc (again registry, as Group Policy settings are stored in registry) to disable $Recycle.Bin for all drives and display delete confirmation box by default, this means modifying both HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER.

In short, the desired effect is, when any user (all user accounts are administrator accounts owned by me, as I am the only user, because the user accounts can get bad and it would be hard to fix the accounts once they are bad, and they are very prone to get bad if a blackout happens while the computer is running...) clicks to delete a file/files on any drive, a delete confirmation box pops up; After confirmation the file(s) is/are deleted directly WITHOUT going through $Recycle.Bin. And there isn't this undeletable $Recycle.Bin folder present in any root directory of the drives.

Of course I know this:

enter image description here

And that exactly what I am trying to avoid. Because I have to manually click Don't move files to the Recycle Bin... checkbox for every drive. Also I can't get rid of this $Recycle.Bin folder, if I delete it, it simply magically reappears after F5...

I found this registry key and value after some Googling:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket]
"NukeOnDelete"=dword:00000001

But the source says it applies to Windows 7, I never used Windows 7, does that value prevent the recreation of $Recycle.Bin? Does it still work on Windows 10?

I also found this:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecycleFiles"=dword:00000001

But when I tried to open that path in regedit an error sound is played and current location isn't changed so the path doesn't exist...

And this:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"ConfirmFileDelete"=dword:00000001

This seems to enable "Delete Confirmation dialog", what I don't know is, does this setting affect all drives? And does it show the dialog, then just move the file to $Recycle.Bin after confirmation if $Recycle.Bin isn't disabled?

How to disable $Recycle.Bin for all users and all drives by default? And how to prevent $Recycle.Bin from returning? Any help is appreciated.


Update

It is strange, I have enabled Do not move deleted files to the Recycle Bin policy, still can get to HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer in regedit... Just pressed F5 and found the key...


Update1

With all above mentioned settings enabled, I tried to delete the $Recycle.Bin folders with Explorer, result: they reappear after pressing F5

Used rd X:\$Recycle.Bin /s /q and they didn't recur after multiple F5 presses so far, I don't know why though, I thought it would have the same effect as deleting it in explorer.exe...


But what does Don't move file to the Recycle Bin. Remove files immediately when deleted. do? What registry key and value does it write? Can anyone tell me?


The $Recycle.Bin folders have reappeared... I have confirmed, clicking on "Recycle Bin" folder will recreate the $Recycle.Bin folders...


I used procmon and got this: enter image description here

It seems that Don't move... sets nukeondelete to enabled on current drive.


I have written a PowerShell script to automatically disable Recycle Bin on all drives, using Get-Volume and Set-ItemProperty;

This is the script I mentioned, I post it here in case anyone else might want to do it:

$volumes=Get-Volume | where {$_.FileSystem -eq "NTFS"}
$Drives=foreach ($volume in $volumes) {
    $DriveLetter=$Volume.DriveLetter
    [string]$ObjectId=($Volume.ObjectId | Select-String -Pattern "Volume{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}\\").Matches.Value.SubString(6,38)
    Remove-Item -Path $('{0}:\$Recycle.Bin' -f $DriveLetter) -Force -Recurse -ErrorAction SilentlyContinue
    New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\$ObjectId" -ErrorAction SilentlyContinue | Out-Null
    Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\$ObjectId" -Name NukeOnDelete -Type DWord -Value 1
    Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\$ObjectId" -Name MaxCapacity -Type DWord -Value 0
}
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -Name NukeOnDelete -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -Name MaxCapacity -Type DWord -Value 0

I am now looking for ways to prevent creation of $Recycle.Bin, I am thinking about group policy and security options.

I have found this:**GPO - How to block creation of folder and files in root directory in Windows 10

Don't know if it will work though(I am only trying to block recycle bin), and how to do it with security options?

2
  • You always put in great effort with your tasks and questions you ask here. Great job there for certain! Commented Jan 10, 2021 at 11:40
  • See if your answer is found in this post.
    – harrymc
    Commented Jan 10, 2021 at 15:15

3 Answers 3

1

Fair enough, I tried to use Group Policy to disable folder creation, but there isn't File System group policy object present in Local Computer Policy>>Computer Configuration>>Windows Settings>>Security Settings, and I don't know how to create it...

I tried to use icacls C:\$Recycle.Bin /deny SYSTEM:(OI)(CI)(F)

Then I deleted the folder via Remove-Item, after pressing F5 the folder didn't reappear, but openning Recycle Bin on desktop immediately made it reappear.

So the $Recycle.Bin folder is permanently removed, until you reopen the Recycle Bin folder on Desktop, so just remove the icon will ensure the folder won't be recreated;

With my previous commands used to enable NukeOnDelete,NoRecycleFiles,ConfirmFileDelete and to disable MaxCapacity, the final code:

New-Item -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -Name "NukeOnDelete" -Type DWord -Value 1
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -Name "NukeOnDelete" -Type DWord -Value 1
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "NoRecycleFiles" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "ConfirmFileDelete" -Type DWord -Value 1
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\NonEnum" -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\NonEnum" -Name "{645FF040-5081-101B-9F08-00AA002F954E}" -Type DWord -Value 1
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{645FF040-5081-101B-9F08-00AA002F954E}" -Force -Recurse -ErrorAction SilentlyContinue
$volumes=Get-Volume | where {$_.FileSystem -eq "NTFS"}
$Drives=foreach ($volume in $volumes) {
    $DriveLetter=$Volume.DriveLetter
    [string]$ObjectId=($Volumes[0].ObjectId | Select-String -Pattern "Volume{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}\\").Matches.Value.SubString(6,38)
    Remove-Item -Path $('{0}:\$Recycle.Bin' -f $DriveLetter) -Force -Recurse -ErrorAction SilentlyContinue
    New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\$ObjectId" -ErrorAction SilentlyContinue | Out-Null
    Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\$ObjectId" -Name NukeOnDelete -Type DWord -Value 1
    Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\$ObjectId" -Name MaxCapacity -Type DWord -Value 0
}
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -Name NukeOnDelete -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket" -Name MaxCapacity -Type DWord -Value 0

It does well what I intended, I wrote all those lines for extra measures to ensure $Recycle.Bin is properly disabled. I will put the code in a single .ps1 file along with many other codes and run it...


Confirmed, restarting explorer.exe will also make the $Recycle.Bin folder reappear, but whatever, at the very least, I can use this script to disable Recycle Bin on all drives automatically, I think it is an accomplishment...

0

To disable deleting to the Recycle Bin, turn on the following option in gpedit.msc:

Local Computer Policy>>User Configuration>>Windows Settings>>Administrative Templates>>Windows Components>>File Explorer (Windows Explorer in older versions)>>Do not move deleted files to the Recycle Bin

Alternatively, you may add the following value to the registry (create the key if doesn't exist):

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecycleFiles"=dword:00000001

Also, you may enable the option for all users by adding the value to HKLM\Software hive (this will override the user setting):

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecycleFiles"=dword:00000001

To enable displaying confirmation dialog when deleting files (which is recommended if you disable deleting to the Recycle Bin), turn on the following option in gpedit.msc:

Local Computer Policy>>User Configuration>>Windows Settings>>Administrative Templates>>Windows Components>>File Explorer (Windows Explorer in older versions)>>Display confirmation dialog when deleting files

Or do this directly in the registry:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"ConfirmFileDelete"=dword:00000001

For all users:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"ConfirmFileDelete"=dword:00000001

Note that customizing these values for all users via gpedit.msc is not available.

-2

FWIW, holding shift when pressing delete is a fast shortcut to deleting files directly. I know this isn't an actual solution, but it's useful to know in general since A. it will work across multiple Windows versions including where things that work on the current ones may fail, and B. it's often respected in other OSes and software such as a number of Linux file managers (which don't really have a system implementation of a recycle bin, but often have a file manager implementation.)

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 20, 2023 at 0:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .