有没有什么方法可以让正在运行的进程删除它自己的可执行文件?
例如,我制作了一个控制台应用程序(单个 exe),在完成一些任务后,它以某种方式删除了 exe 文件。
我必须向某人发送一个文件。我希望它在完成预期任务后将其删除。
在 Windows 中有没有办法做到这一点
最佳答案
一种方法是使用 MoveFileEx具有 MOVEFILE_DELAY_UNTIL_REBOOT
标志和 NULL
目标的功能。根据文档,这是:
registers the lpExistingFileName file to be deleted when the system restarts. If lpExistingFileName refers to a directory, the system removes the directory at restart only if the directory is empty.
关于windows - 程序如何删除自己的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1606140/