Reputation: 1685
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 key:
Command.com /c del c:\some file.ext
but I observe a problem with paths with embedded spaces. I have to say I tried this one too:
Command.com /c del "c:\some file.ext"
But this does not resolve the problem, but make it worst: not deletion of any file, regardless of embedded spaces!
What is the correct way to delete files from my program delayed to the next reboot?
Thanks.
Upvotes: 6
Views: 3670
Reputation: 125708
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);
Upvotes: 30
Reputation: 234504
Use cmd.exe instead. That's the "new" command prompt since Windows NT.
cmd.exe /c del "c:\some file.ext"
Upvotes: 2
Reputation: 46060
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.
Upvotes: 1