AshikNesin.com

Notes on Tech & Life

  • Home
  • Programming
  • Tutorials
  • Make Money
  • About
  • Contact
You are here: Home / Programming / C/C++ / How to create Self-Destruction program in C/C++

How to create Self-Destruction program in C/C++

By Ashik Nesin 1 Comment

hacker_using_laptopWhether 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 🙂

Self Destruction Program in C/C++
C
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

 

Self Destruction in Linux
C
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.

  • Facebook
  • Twitter
  • Google+
  • StumbleUpon
  • Buffer

Recommended Guides for you

  • How To Shutdown computer using C ProgramHow To Shutdown computer using C Program
  • How to Create fake virus using NotepadHow to Create fake virus using Notepad
  • Top 5+ websites to Transfer Large Files OnlineTop 5+ websites to Transfer Large Files Online
  • How to Make Folders Case Insensitive in Web Hosting (Apache Server)How to Make Folders Case Insensitive in Web Hosting (Apache Server)

Filed Under: C/C++ Tagged With: self destruction in linux, self destruction in windows, self destruction program in c

About Ashik Nesin

Founder of HugeThoughts. I've been freelancing for many years and now focuses on providing quality resources &tutorials that I hope others find interesting too..
Contact me anytime for anything- I’d love to hear from you!

Comments

  1. poobalan says

    October 22, 2015 at 4:38 am

    This is too complicated….how to learn from the beginning…..

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Articles

  • How To Record Your iPhone Screen in 3 Easy Steps
  • Official Link to Download Mozilla Firefox Standalone Offline Installer [Latest ]
  • How to Automatically Login to Windows 8.1/10 in 60 Seconds
  • How to create Self-Destruction program in C/C++
  • Top 5 open-source alternative for Photoshop
Copyright © 2020 · – till the end of time, Ashik Nesin