self-destruction vb program

I am tring to do self-destruction program in vb, but I got
path/file access error number 75. Here is my code :

Kill App.Path & "\" & App.EXEName & ".exe"

what's wrong ? How to correct it ?
Who is Participating?
rmichelsConnect With a Mentor Commented:
You can't delete the EXE because you are currently running it.  Windows will have it marked as in use.

what you could do is create 2 exe files (two VB programs).

say the one you want to destroy is called APP.EXE.  The other is called DELAPP.EXE.  When you want to destroy your application, have it SHELL DELAPP.EXE and immediately End.  Then in DELAPP, delete APP.EXE.  You'll still have DELAPP laying around though.  You may have some timing issues, with DELAPP  trying to delete may have to keep retrying the KILL command, until it succeeds.

Make sure you check if APP.EXE is there, before you delete it, that way DELAPP won't be stuck in an infinite retry loop if someone happens to run it, after it has done it's deletion

howtobeAuthor Commented:
I think I just understand half of it. Can you be more clear or will you show me the example ? Thanks
In the primary app, the one you want to be deleted..I put in form1_Unload

  Shell "d:\deleteit.exe" (of course modify the path to your specs)

at the end of the unload sub

I created another app, called deleteit.exe.

In project settings, startup is Sub Main

Option Explicit

Sub Main()
    Dim b_deleted As Boolean
    Dim counter as integer
    If Dir("d:\project1.exe") <> "" Then 'modify path for your specs
        While Not b_deleted and counter < 100
            On Error Resume Next
            Kill "d:\project1.exe" 'modify path
            If Err.Number = 0 Then
                b_deleted = True
                counter = counter + 1 'keep from infinite loop
            End If
    End If
End Sub

howtobeAuthor Commented:
I am sure these code will work but please give
me 2 days to verify. I am busy right now.

Thank a lot.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.