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
Printable View
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
kill app.path & "\myprog.exe"
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.
You can read about doing this here & here
Of course that is another option. There is an API function (MoveFileEx) that can delete a file at the next reboot.
Pass MOVEFILE_DELAY_UNTIL_REBOOT for the dwFlags parameter, and pass vbNullString for lpNewFileName.
This is for NT based OS's
For win 9x you need to use the method mr_metal_hed mentioned.
Hi Phinds,Quote:
Originally posted by phinds
kill app.path & "\myprog.exe"
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??
Thanks Frans C and mr_metal_hed,
But still not clear to me..
Any better way?
Anyone will give me code?
Thanks in Advance...
Anita
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.
:eek: That kind of takes the fun out of it, doesn't it? besides, you never specified the OS...Quote:
Anyone will give me code?
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
Would that work?
Hai,
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.
Ok.
[email protected]
I can only blame my brain dead response on the fact that I hadn't yet had breakfast when I posted.Quote:
That wont work, because the executable is in use, and can't be deleted
Sounds like MarkT has the solution
Hi mr_metal_hed, I agree with u. But sometimes u needs the program ASAP. Isn't it? Otherwise no problem.Quote:
Originally posted by mr_metal_hed
:eek: That kind of takes the fun out of it, doesn't it? besides, you never specified the OS...
Thank You very much MarkT,Quote:
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.
Nice code and working fine...It solved my problem..
Million Thanks;)