8

I use the below command to delete some files after reboot the machine:

MoveFileEx(PChar(File_Address), Nil, MOVEFILE_DELAY_UNTIL_REBOOT);

How can i cancel execution of this command and prevent files from deleting after reboot?

JRL
  • 3,363
  • 24
  • 36
Armin Taghavizad
  • 1,625
  • 7
  • 35
  • 57

2 Answers2

14

Files you enqueue for deletion this way are placed in the registry under HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations. Perhaps you can delete entries from there, to prevent the files from being deleted. I couldn't find an API function for this.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • 4
    +1. You can delete the entry from that registry key using Delphi's TRegistry class or the API directly, but note that on Vista and above you'll need to be logged in as Administrator to do so (normal users can't write/delete from HKLM). The better solution, of course, is to not create the entry in the first place until you're absolutely certain you want the file deleted. :) – Ken White Oct 15 '11 at 15:38
1

I guess you could copy the file (since it hasn't been deleted yet) and then use

MoveFileEx(copy_of_file, original_file, MOVEFILE_DELAY_UNTIL_REBOOT)

to put it back in place during the reboot.

As Ken White has pointed out, though, it would be much much better to avoid this situation in the first place.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • It is [indeed](http://msdn.microsoft.com/en-us/library/Aa365240.aspx) documented. _"The move and deletion operations are carried out at boot time in the same order that they are specified in the calling application. "_ – CodeCaster Oct 16 '11 at 11:23
  • @CodeCaster, thanks, and well spotted. I've edited accordingly. – Harry Johnston Oct 17 '11 at 00:12