Empty recycle bin

Please use below script to clear Recycle bin ,

Note: This will clear recycle bin for all users.


import os;
import ctypes

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

with disable_file_system_redirection():
    clear=os.popen('rd /s /q %systemdrive%\$Recycle.bin').read();
    print(clear);

Sample output would be,

FINISHED SUCCESS

I just ran this on Win 7 enterprise desktop and it doesn’t work. The status shows as Finished success on the Procedure Log status.

Hi @ikondata

Do you mean the recycle bin is still not empty on the endpoint?

Did you run as a system user or logged in user?

Ilker

Tried both user types and did not work.

Hi @ikondata

Your request to resolve script issue is in progress. I will let you with updated procedure.

Hi @ikondata

I have tested the script and i am unable to reproduce the issue. It works with our Windows Enterprise x64 bit.

I request you to test below script,

https://forum.mspconsortium.com/forum/script-library/4962-empty-recycle-bin

If problem continues , please let me know. We can schedule Teamviewer session and troubleshoot .

Thanks,
Kannan