程序如何删除自己的可执行文件 [英] How can a program delete its own executable

查看:159
本文介绍了程序如何删除自己的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,我制作一个控制台应用程序(单独的exe),在做一些任务之后以某种方式删除exe文件。



我必须向某人发送单个文件。而且我希望在完成任务之后删除它。



有没有办法在Windows中执行

解决方案

一种方法是使用 MoveFileEx 函数与 MOVEFILE_DELAY_UNTIL_REBOOT 标志和 NULL 目的地。根据文档,这样:


注册在系统重新启动时要删除的lpExistingFileName 文件。如果lpExistingFileName 指的是一个目录,系统会在目录为空时重新启动该目录。



Is there any way that a running process can delete its own executable?

For example, I make a console application (single exe) and after doing some tasks it somehow deletes the exe file.

I have to send a single file to someone. And I want it deleted after it does its intended task.

Is there anyway to do it in Windows

解决方案

One way to do this is to use the MoveFileEx function with the MOVEFILE_DELAY_UNTIL_REBOOT flag and a NULL destination. According to the documentation, this:

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.

这篇关于程序如何删除自己的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆