Making CTRL+Z for Recycle Bin only restore deleted item - and in the background

Microsoft Windows
Post Reply
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Making CTRL+Z for Recycle Bin only restore deleted item - and in the background

Post by SS##66 »

I have this script

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "explorer.exe shell:RecycleBinFolder", 9

WScript.Sleep 1111

WshShell.SendKeys "^z"
WshShell.SendKeys "%{F4}"
which executes the CTRL+Z on a Windows Explorer with opened Recycle Bin in its window. And I have two issues with it


#1] Aside from un-deleting last item[s] that was [or were] deleted, it also executes an un-move command- i.e. when the last action was not a deletion but movement. How can this be avoided? How to only restore items from Recycle Bin

#2] How to make this run in the background? If I change this to

Code: Select all

WshShell.Run "explorer.exe shell:RecycleBinFolder", 7
then it does not work. I need either for the Windows Explorer window to be open minimized - or not opened at all, thus some potentially totally different script that will send to the operating system proper commands



I am using Windows 10 Enterprise 20H2 19042.746 x64
User avatar
Simon Sheppard
Posts: 186
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Making CTRL+Z for Recycle Bin only restore deleted item - and in the background

Post by Simon Sheppard »

Ctrl-Z is a generic undo command, so that is always going to undo any Windows Explorer action: renames, moves, additions, deletes.

So you are going to need a different approach, the recycle bin might contain hundreds of items deleted over weeks or months, so you first need to identify what to restore and make sure any required subfolders are still in place.

You will need to consider:
Single files that have been deleted.
Multiple files that have been deleted.
Folders containing files which have been deleted.
Empty Folders which have been deleted.

VBScript or PowerShell are likely better than CMD for this, heres a VBscript by Courtney Jimenez which deletes from the Recycle Bin which you could adapt to do a partial restore.

The difficult part is going to be identifying what was recently deleted, when you delete a file or folder the date time of the deletion is recorded in the recycle bin (which you can view using DIR /a "C:\$Recycle.bin" ). However for the files inside a deleted folder, they will still display their last modified date/time.

Unpicking all of that would be gnarly.
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Re: Making CTRL+Z for Recycle Bin only restore deleted item - and in the background

Post by SS##66 »

Thank you for this roadmap - but it is way too complex for my very limited coding skills

What about the
SS##66 wrote: 2023-Jan-26, 12:57 pm [...]
#2] How to make this run in the background?
[...]
issue?
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Re: Making CTRL+Z for Recycle Bin only restore deleted item - and in the background

Post by SS##66 »

SS##66 wrote: 2023-Jan-26, 12:57 pm [...]
#2] How to make this run in the background?
[...]
Well, anyone?
Post Reply