How can I delay file deletion until next reboot from my program?

前端 未结 3 1371
面向向阳花
面向向阳花 2021-01-03 01:11

My application needs to delete some files, but this should happen until next windows startup.

What I\'m doing now is to write this string value in RunOnce registry k

相关标签:
3条回答
  • 2021-01-03 01:40

    Use cmd.exe instead. That's the "new" command prompt since Windows NT.

    cmd.exe /c del "c:\some file.ext"
    
    0 讨论(0)
  • 2021-01-03 01:52

    Just a guess: Looks like you are running "DOS" command.com that works with short file names only. If you are on Win2K and later, use cmd.exe instead of command.com and yes, use double-quotes.

    0 讨论(0)
  • 2021-01-03 01:53

    Don't use RunOnce, and don't use Command.com. If you insist on using something, use %COMSPEC% /c instead. You have a better option, though.

    Use MoveFileEx with the MOVEFILE_DELAY_UNTIL_REBOOT flag instead:

    if not MoveFileEx(PChar(YourFileToDelete), nil, MOVEFILE_DELAY_UNTIL_REBOOT) then
      SysErrorMessage(GetLastError);
    
    0 讨论(0)
提交回复
热议问题