windows - 程序如何删除自己的可执行文件

标签 windows file process

有没有什么方法可以让正在运行的进程删除它自己的可执行文件?

例如,我制作了一个控制台应用程序(单个 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/

相关文章:

windows - 在 Windows 8 上声明每个窗口的高 DPI 感知

C++:为什么在 Eclipse Neon 中运行的相同代码在 Visual Studio 2013 中会产生不同的输出?

c - 在 C 中访问目录

python - 在Python中打开文件时防止应用程序关闭

project-management - 需要流程指南

c# - 在 C# 中添加字符串,编译器是如何做到的?

c++ - 如何在 c/c++ 中从 Windows PC 获取唯一的硬件/软件签名

java - 我可以使用 Intellij Idea 为 Greenfoot 开发吗?

C++ 将 CSV 文件解析为 vector vector : Loosing string 1st character

process - Erlang:杀死所有在后台运行的进程