0
I've been looking for the most convenient way to tell Windows 10 to delete certain files upon rebooting. Having a right-click context menu option seems to be the most efficient solution. I've stumbled across the following registry entries that give me such an option, but on Windows 10 x64 it isn't actually deleting the files I apply it to.
[HKEY_CLASSES_ROOT\*\shell\Delete on reboot\command]
@="CMD /E:OFF /C REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Currentversion\\RunOnce /v \"Del %1 OnNextReboot\" /d ^\"cmd.exe /c DEL /F /Q \\\"%1\\\"\" /f\""
[HKEY_CLASSES_ROOT\*\shell\Open]
[HKEY_CLASSES_ROOT\Folder\shell\Delete on reboot\command]
@="CMD /E:OFF /C REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Currentversion\\RunOnce /v \"Del %1 OnNextReboot\" /d ^\"cmd.exe /c RD /S /Q \\\"%1\\\"\" /f\""
Apparently this registry code has been floating around the internet for a long time, and the most updated information I could find about it was someone saying that it worked for them on Windows 7. Is there some way I can modify it to work on Windows 10?
Thank you.
Thank you! Unfortunately this isn't working. Everything gets entered into the registry just fine, and I know that the movefile.exe is being executed when I select the right-click option, but the files just aren't being deleted after rebooting. Actually, let me try manually using movefile.exe on a file and see if that works... I'll report back asap. – vertigoelectric – 2016-09-07T14:47:31.440
Ok. Let's know how it goes.. It worked fine here when I tested. – w32sh – 2016-09-07T14:53:43.310
It's not deleting the files. However, now that I understand how to use the registry to apply basically any executable/script to a file using right-click, perhaps I can use something other than movefile.exe to do this... but still... I'd like to figure out why it's not working. – vertigoelectric – 2016-09-07T14:56:01.970
Ah, in my test batch file I've added "pause" and now see that I'm getting errors. I'm testing two files, one of them has a special character. The normal file returns "Error: 5", the other file returns "Error: 123". I'm going to research these. – vertigoelectric – 2016-09-07T15:00:02.933
Perhaps the file you're trying to delete is owned by "TrustedInstaller"? – w32sh – 2016-09-07T15:00:03.723
Error 5 is access denied. Someone suggested taking ownership of the file. I do have a right-click option for that. However I'd prefer to not make this multiple steps (hence making it a right-click option to begin with). I don't understand why I'm constantly having to take ownership of files. – vertigoelectric – 2016-09-07T15:03:44.850
This can happen if Ti is the owner. You can combine takeown + movefile.exe (using a vbscript or PS) and implement it in the context menu. – w32sh – 2016-09-07T15:07:17.480
I finally got it working. I don't have enough experience with VBS or PS, so what I did was create a batch file containing the commands for takown and movefile. I then used a BAT to EXE converter to make it an EXE with admin rights, and pointed to that in the registry entry. It still doesn't delete the files with the special character, but I'll just stop using that character for now. I've upvoted your answer, but feel I should post what I did as its own answer. Thank you so much for your help! – vertigoelectric – 2016-09-07T15:46:19.753