Link to home
Start Free TrialLog in
Avatar of kurian2z5
kurian2z5Flag for India

asked on

App Delete its own exe on terminate

How do i make a program delete its own exe when it closes. (Without shelling another exe to delete it on Unload)
Avatar of RogueSolutions
RogueSolutions

Can you control the opening of the EXE?  If so, I'd launch a different EXE that in turn starts your actual "program" and waits for it to complete before deleting it.

You can watch an exe via VB (don't have code to hand though) or by using Installer software such as Wise - which can launch a program with an optional "wait for exit" parameter.

Your actual program needn't be named as an EXE if you are trying to protect it.

There won't be a way of getting rid of your launcher app though, but without the main program it will be useless.

Simon
Avatar of Mike Tomlinson
You can't.  This would be like trying to pull a stool out from under your feet while you are standing on it.

You must use some kind of external application to delete the EXE, whether it be a batch file or another application.

~IM
You could try using:

      Kill App.Path

but I expect it will be locked, as Rogue and IM have said...

J
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kurian2z5

ASKER

Are you sure there is no way to make an app delete itself without using another external program ot bat ? BTW how do you shell an app not named .exe like Rouge mentioned, like the .icd encrypted file Safedisc 1 used ?
You can't have an EXE delete itself as others have indicated.  To execute the deletion the EXE must be running therefore the deletion will fail because the file is in use.

---

The Visual Basic command Shell assumes that the parameter given is an EXE and runs it (have just tested this - on Win2K at least)

So ...

     Shell "C:\myfile.ext", vbNormalFocus

will run myfile.ext (or whatever you want to call your file).  Doesn't matter if the ext is an existing one, e.g. txt

The name Shell in VB is a bit misleading.

---

To achieve your goal you'll need two apps, one to run/watch and/or delete and your actual app.

Personally I think the self-creating BAT file proposed by Ark / List244 is a very tidy solution.  



Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

ShellExecute Me.hwnd, "OPEN", "FILENAME", "", "", 1

That will launch another file type.
Btw List244, i wanted to know how to execute an .exe file that has been renamed to some other extension (execute it like a program).

Like in SafeDisc 1, the exe is encrypted and stored as a .icd file. When the game is run using the launcher exe, the icd file is decrypted and executed from memory without being actually written to the harddisk as a new file. When i view running processes it shows the game.icd is running.

How do i do this ?
The VB shell function will launch an exe that is not named
.exe.  As far as unencrypting the exe, can't help you there.
Kurian - How do you know the icd file is encrypted?  

It could well be an normal exe that expects a particular command-line parameter to make it work (so if you just renamed it to .exe and ran it manually that would fail).

The launcher app you mention does the clever 'protection' stuff.  You can mimic this sort of thing with two VB apps - one calls the other with a 'key' of some sort.  Not sure why you'd want to of course.

I didnt know you could shell an executable that is not named .exe, i tried it and it works.
But how do decrypt an encrypted file and execute it from memory without having to save it to a file ?
Kurian

There are plenty of tricks people can pull that might look like encryption that aren't.

1) Say I give you a file called MyTrick.XXX

2) Now really it is an EXE that will only run if passed a command-line parameter of "PleaseRunMeNow".  if it doesn't get that command line it doesn't run.

Unless I tell you part (2) you'll never know how to get it going so it 'encrypted' as far as you are concerned

---

If their file really is and encrypted file that is run from within memory then that's very clever but why bother?


SafeDisc is a CD copyprotection method for games. There is a dummy exe and a .icd file. You have to run the dummy exe, it checks for the original Disc and then the .icd file is decrypted and run.

There are tools like UnSafeDisc that decrypt the .icd file and give you the original exe which you can run.

I just used this as an example. I want to encrypt a third party exe so that my launcher program will decrypt it and run it only if you provide a correct password to the launcher or something. So It should be independent of the exe Im encrypting.

One more thing. I can shell an exe renamed to another extension with VB's shell function, but how do i run it from windows ?
If you encrypt it yourself its easy.
Go to google, and search an encryption method that you like.
Encrypt the exe then have another program that decrypts
it if the password is correct. If you need more help than this
it is time to open a new question. Rules of EE do not allow
changing your question to get more answers. The point system
has a reason.