Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a running excutable delete its own file

Tags:

c#

delete-file

For example,

I have an excutable TrashClean.exe running. I want it to delete all files I don't want and also delete itself (TrashClean.exe on hard drive) at last step.

I am wondering if it's possible in C#?

like image 278
user648912 Avatar asked Mar 14 '11 20:03

user648912


People also ask

Can an EXE file delete itself?

If the program or the EXE is not running, it will be able to delete itself. Security software usually terminates these programs and quarantines them. However, when the program is in memory of the OS, it will not able to delete itself.

How do you write a program such that it will delete itself after execution?

Using remove() function in C, we can write a program which can destroy itself after it is compiled and executed. Explanation: This can be done using the remove function in C.

How do I overwrite an EXE file?

1) Rename the currently-running exe (it will continue to run just fine). 2) Copy the new exe to the old exe's location. 3) Start the new exe, establishing IPC with the currently-running exe. 4) Have the new exe delete the renamed old exe after the old exe stops running.

How do I permanently delete exe files?

To permanently delete files on Windows, send them to the Recycle Bin and then empty the Recycle Bin to delete them for good. Once the bin is empty, you can't recover the files unless you have data or file recovery software. And even that may not work, because recovery software is no guarantee.


1 Answers

Please see How To Make Your Application Delete Itself Immediately:

I'm sure you've all said to yourself or someone at the office at one point or another, "<snort> You idiot. Don't you know a Windows application can't delete itself? I bet you don't even know how to type high ASCII characters using the ALT key and the number pad, gahhhh.."

Sure, there are ways to have a file delete itself on the next reboot... And you can even resort to an external program or batch file to do the work. But I just came up with a nifty way of doing it without leaving a visible trace that the application ever existed!

like image 82
Andrew Hare Avatar answered Oct 17 '22 09:10

Andrew Hare