Hi all,
I want that my program will kill itself after executing.
How to do this?
To be clear, I don't want to make for any ill purpose...
Help...
Anita
Can't imagine life without VB
(Various Boyfriends)
That wont work, because the executable is in use, and can't be deleted.
You could create a (temporary) batch file, that deletes the executable, and after that deletes itself (a batch file can delete itself). Shell the batch file and immediately close the program.
There could be a timing problem though, because the executable could not be finished closing itself when the batch file tries to delete it. I think it is best to put the code in the terminate event, so it executes as late as possible (you have to put something like Set Form1 = Nothing in the unload event, otherwise the terminate event isn't triggered).
I remember that this question has been asked before, so you could try to search for something like "program delete itself"
Does that actually work? I always add a line to the rename section of Wininit.ini to delete my program.
[rename]
NUL=C:\MyProg.exe
Of course this doesn't happen until the next reboot. Ever notice on loading windows shows "Please wait. Updating your file configuration" or something.... it's deleting files etc. This is how a lot of programs delete their components when you uninstall them.
Originally posted by phinds kill app.path & "\myprog.exe"
Hi Phinds,
I tried it..but it sems to be not working...
i think its not working as the exe is running.
U can't kill/delete the file if it is running..
Anyone explan??
Can't imagine life without VB
(Various Boyfriends)
Attached is a sample program that will delete itself. Basically what is does is it write a batch file that will attempt delete the exe. It will loop until the exe is deleted and then it deletes the batch file.
Go ahead and compile the app and place it somewhere where it is easy to watch. Run it and close it and watch it disappear.
would it be alright if you installed 2 exes.. the self deleting one and a time-delay deleting one? That way they would keep the deleting one. You could make it like
Sub Form_Terminate()
Shell "C:\MYTIMEDELAYEDKILL.EXE " & app.path & app.exename & ".exe"
End Sub
Killing means u can't delete the file,
But u can make the program run once only.
This can be done by creating a flat file if it is not there and exiting if it is there. First time it will create the file and executes, From second time onwards it exits simply as the file is already there.
Originally posted by MarkT Attached is a sample program that will delete itself. Basically what is does is it write a batch file that will attempt delete the exe. It will loop until the exe is deleted and then it deletes the batch file.
Go ahead and compile the app and place it somewhere where it is easy to watch. Run it and close it and watch it disappear.
Thank You very much MarkT,
Nice code and working fine...It solved my problem..
Million Thanks
Last edited by anita2002; Aug 30th, 2002 at 07:17 AM.
Can't imagine life without VB
(Various Boyfriends)