I'm not sure what languages you are familiar with in programming, but VB has a easy way to do this. Write a simple program that launches your application itself using the SHELL command. Then a routine to periodically, say every second or so, attempt to "activated" that running application. If successul, the loop continues. Otherwise an error occurs and you trigger a re-launch of the program. I tried doing this for a program once, attempting to tell when it exited so I could do something that need to be done after it exited but NOT while it was running. For some reason I could not get the Application ID/activation method to work consistently so I went about it a different way. IN WINDOWS 95 AND ABOVE OPERATING SYSTEMS YOU CANNOT DELETE A PROGRAM FILE THAT IS CURRENTLY RUNNING. Making use of this basic fact I wrote a loop that tried to delete the file every second. The loop continued so long as their was a error, indicating the application was still running. Now at the beginning of the code the program makes a copy of the .exe file that it is trying to delete for backup, then launches the original, then the deletion attempt loop begins. Once this loop is finally successful and the file is deleted, indicating the program is no longer running, it jumps to code that restores the file file from the backup to put things back the way they should be. This method has worked flawless and effectively for me. It is also very quick..the deletition routine, set on a 1 second interval loop, deletes the file the very second the program ends and unloads, and rest of the code runs immediately.
|