Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Self-destructing executable

Status
Not open for further replies.

JonnyV

Programmer
Mar 4, 2002
7
0
0
CA
Hey all;

I've never seen this done, so I doubt there will be a "clean" way to do it. Perhaps someone can prove me wrong.
=)

I want to create a self-destructing executable; that is, I want the standalone app to run once successfully, then be deleted without going to the recycling bin. This is for a one-time "fix" utility that I don't want the client to have after it's done.

Is there any way to do this?

Thanks in advance,
Jon
 
You could run it from a DOS batch file - the DOS DEL command doesn't send the file to the recycle bin....
 
Could you not just create 2 executables.
The first program uses the File system object to check if the second one is there and run it, then use the FSO again to delete the second program.

Not quite what you where looking for, however would do the job.
 
Please refer to this older thread on how to have the EXE create and run a batch file that deletes the EXE then deletes itself.

thread222-277226
 
If the primary application is not already written, you can write it to look for the presence of the Update file the Update's installation directory. If it finds it, it deletes it. If it does not, it goes on to run.

The user would install the Update and it would be installed into some mandatory directory
(e.g. C:\Program Files\MyProg\Update).
They would then run the Update external from the primary application.

The next time they ran the primary - goodbye update program!

Good Luck,
I_Forgot
 
There are alot of good examples of this at . Some of them don't require a separate batch file. Here are some examples:


You can try these! [sup]Tiger[/sup][sub]Flight[/sub] [tiger]
Everyone has their two cents worth. Lets all try to donate our two cents and maybe we all can come up with a Dollars worth of advice!!!!!
 
Great ideas guys! (gals ?)
=)

Thanks go to everyone who replied.
I took some ideas from here and there, and came up with the below code. As you can see, it's defined in the Form_Unload event of the application so that it doesn't try to delete the app while it's being used. Feel free to use this as you you want.

Code:
Private Sub Form_Unload(Cancel As Integer)
   
   ' determine the path for the batch file
   Dim sPath As String
   sPath = App.Path & "\del.cmd"
   
   ' open the batch file , overwriting any existing file by the same name & ext
   Open sPath For Output As #1
   Print #1, "del " & Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)
   Print #1, "del " & Chr(34) & "del.cmd" & Chr(34)
   Close #1

   ' run the batch file
   Call Shell(sPath, vbHide)
End Sub

Happy Coding
=)

-Jon
 
Depending on the speed at which your app unloads, it's possible that the .bat file may execute before the app has finished closing. ( and it may be random. One time it will work, and the next time it wont ) In this event, the EXE will not be deleted.

If you use the loop in the .bat file as my example shows, then you won't have this problem.

Robert
 
Hey Robert

Thanks for the find. I skipped over your post by mistake.
=)

Thanks again,
Jon
 
If you only want the app to run once, while it is running you could get the app to open itself as a random acess file and overwrite it self with chr(0)'s.

The file would still be there but would obviously never run again, not as neat as having nothing left at all, but a quick easy solution.

I used to use this sort of method to hide passwords and counters inside the application that was running.

Dazz GuiltyMaggot - The best rock band in the world!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top