SELF DESTRUCTION OF (.EXE)

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
10 posts Page 1 of 1
Contributors
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

SELF DESTRUCTION OF (.EXE)
noypikami
before i came up with this tutorial, i wondered how to self destruct an exe file after a given
span of time. when you have a software like parental control you can have an option saying-
"SELF DESTROY ON" and a textbox to provide a date. the end date will be the destruction date
of the file and the beginning date is where when you have activated it. SELF DESTRUCTION OF
EXE FILE IS VERY IMPORTANT FOR SOME REASONS.

so let's start:

create: one BUTTON, ONE LABEL AND A TIMER

below Form1 (public class form1) add this code:======================
Code: Select all
 Dim timelimit As Integer = 10    'set the time for countdown
create a function to get the current running .exe name :================
dont use the product name, because if the user change the name of the exe file the batch
file cant find it anymore (this function is very important in order for the batch file
to locate the current exe file that is renamed
Code: Select all
 
    Private Function getfilename(ByVal path As String, ByVal b As String) As String
        Dim word As String = path
        Dim label As String = b
        Dim lines() As String = word.Split("\")

        For Each line As String In lines
            If line.ToLower.Contains(".exe") Then
                label = line
            End If

        Next
        Return label
    End Function
on button.click add this code:==============
Code: Select all
  Timer1.Start()  'interval is= 1000
on the timer, add this code================
the timer will stop when it reach the given time and create a batch file , the batch file
will start immediately, kill the current process using cmd, and delete the exe file
as soon as the exe file is deleted the batch file will delete itself.
Code: Select all
  timelimit -= 1
       
        Label1.Text = "TIME LEFT IN SECONDS: " & timelimit

        If timelimit <= 0 Then
            Timer1.Stop()
     
            Dim filename As String = getfilename(Application.ExecutablePath, "true")
            Dim f2delet As String = Application.ExecutablePath  'the full path of exe file 
            Dim sb As New System.Text.StringBuilder ' string bulider=- to build the text and save as batch file
            sb.AppendLine("@echo off")
            sb.AppendLine(":Begin")
            sb.AppendLine("taskkill /f /im """ & filename & "") 'kill the exe file when its running
            sb.AppendLine("del /s /q " & """" & f2delet & """") 'force delete the exe file based on the full path
            sb.AppendLine("if exist " & """" & f2delet & """" & " goto :begin") ' if not deleted then go back- this is infinate
            sb.AppendLine("DEL ""%~f0""")   'enable the batch file to delete itself after it delete the exe file
            IO.File.WriteAllText(Application.StartupPath & "\selfdelete.bat", sb.ToString())
            Process.Start(Application.StartupPath & "\selfdelete.bat")
        End If


============that's it =====================================
so the FULL CODE WILL BE LIKE THIS:
Code: Select all
Public Class Form1

    Dim timelimit As Integer = 10    'set the time for countdown
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        timelimit -= 1
       
        Label1.Text = "TIME LEFT IN SECONDS: " & timelimit

        If timelimit <= 0 Then
            Timer1.Stop()
            ' function to get the filename from executable path, even if the user change the name of exe file it will still be deleted soon
            Dim filename As String = getfilename(Application.ExecutablePath, "true")
            Dim f2delet As String = Application.ExecutablePath  'the full path of exe file 
            Dim sb As New System.Text.StringBuilder ' string bulider=- to build the text and save as batch file
            sb.AppendLine("@echo off")
            sb.AppendLine(":Begin")
            sb.AppendLine("taskkill /f /im """ & filename & "") 'kill the exe file when its running
            sb.AppendLine("del /s /q " & """" & f2delet & """") 'force delete the exe file based on the full path
            sb.AppendLine("if exist " & """" & f2delet & """" & " goto :begin") ' if not deleted then go back- this is infinate
            sb.AppendLine("DEL ""%~f0""")   'enable the batch file to delete itself after it delete the exe file
            IO.File.WriteAllText(Application.StartupPath & "\selfdelete.bat", sb.ToString())
            Process.Start(Application.StartupPath & "\selfdelete.bat")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()  'interval is= 1000
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    'function to get the filename  from of the current exe file- dont use the product name, because if the user change the name
    'of the exe file the batch file cant find it anymore (this function is very important in order for the batch file
    'to locate the current exe file that is renamed
    Private Function getfilename(ByVal path As String, ByVal b As String) As String
        Dim word As String = path
        Dim label As String = b
        Dim lines() As String = word.Split("\")

        For Each line As String In lines
            If line.ToLower.Contains(".exe") Then
                label = line
            End If

        Next
        Return label
    End Function
End Class
HERE'S THE SAMPLE EXE :::
SELFDELETE_exe file.rar
HERE'S THE FULL PROJECT:::
SELFDELETE-full project.rar
You do not have the required permissions to view the files attached to this post.
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: SELF DESTRUCTION OF (.EXE)
smashapps
Interesting tutorial +rep

What use would there be in destroying itself though?
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: SELF DESTRUCTION OF (.EXE)
Shim
Find my programs on Softpedia
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: SELF DESTRUCTION OF (.EXE)
noypikami
Thank you for the rep.
#smashapps , it's useful when you make an app like K****ger / pc monitoring software.
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: SELF DESTRUCTION OF (.EXE)
Codex
It's also useful for RATs and other hacking tools where you want to remove the program and evidence.

* Disclaimer, this ^ is all illegal :P *
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: SELF DESTRUCTION OF (.EXE)
smashapps
Thanks #noypikami and #Codex
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
anthonygz
Member
Member
Posts: 48
Joined: Sun Feb 13, 2011 7:25 pm

Re: SELF DESTRUCTION OF (.EXE)
anthonygz
Besides just hacking tools, you can inquire this in Updating your application or performing other functions inside of the batch file itself ya know? A very well written tutorial my dear sir.
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Re: SELF DESTRUCTION OF (.EXE)
benji_19994
#Codex a RAT ain't illegal to have installed on a computer or a server you own it's only illegal to have on someone else's computer doing malicious stuff

you could have a program that removes itself when the computer is rebooted then when it's restarted it could be reprogrammed to start a newer version of the program from a dropbox.
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: SELF DESTRUCTION OF (.EXE)
Codex
#benji_19994 that's true, but a RAT is usually associated with criminal or malicious activity. There are some legitimate uses to it, but it's less likely that case in most of the RATs.
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: SELF DESTRUCTION OF (.EXE)
Shim
Codex wrote:
#benji_19994 that's true, but a RAT is usually associated with criminal or malicious activity. There are some legitimate uses to it, but it's less likely that case in most of the RATs.
BTW It was introduced for parenting purposes and network administrating purposes.
Find my programs on Softpedia
10 posts Page 1 of 1
Return to “Tutorials”