Whether you want to prank your friends or add security to your confidential information. Self Destruction is
would be really cool way to play around.
Just like in the Hollywood movies you can have your own Self Destruction program in no time.
I hope you have basic C/C++ programming knowledge and have a windows based IDE like Dev C++ or
Code:Blocks using which we are going to compile our program.
Here is the self destruction program in c language.
It’s just a basic version. Just change the code according to your needs 🙂
WINDOWS OS
Windows OS does not allow us to EASILY delete the file which is currently loaded in memory(application is running).
That’s why we are going to create a bat file in temporary directory and use it do delete our application.
I think it’s the easiest way.
Do you know any other way… ?
That’s GREAT!
Share it with us in comment below 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include<stdio.h> #include<string.h> #include<windows.h> #define MAX _MAX_PATH void SelfDestruct(); int main(int argc, char *argv[]) { SelfDestruct(*argv); return 0; } void SelfDestruct(char *exepath[]) { char batname[MAX]="selfdestruct.bat"; char batcmd[MAX] =":Repeat\ndel \"%s\"\nif exist \"%s\" goto Repeat\ndel \"%s\"" ; char temppath[MAX]; GetTempPath(MAX,temppath); FILE *fp; chdir(temppath); fp=fopen(batname,"w"); fprintf(fp,batcmd,exepath,exepath,exepath); strcat(temppath,"\\"); strcat(temppath,batname); fprintf(fp,"\ndel %s",temppath); fclose(fp); ShellExecute(NULL,"open",temppath,NULL,NULL,SW_HIDE); } |
Linux OS
Here’s the code for Linux-style OS. I referred it from StackOverFlow
1 2 3 4 5 6 |
#include<stdio.h> #include <unistd.h> int main(int argc, char* argv[]) { return unlink(argv[0]); } |
Let me know your thoughts in comment below.
This is too complicated….how to learn from the beginning…..