I have a VB6 application that needs to update it's self. For this purpose, the PM has recommended using a batch file that is to be launched from the application. The batch file should kill the process, download the new version from a local server, overwrite the old files and launch the application again.
My problem with this is that I am not sure that taskkill returns control the the parent only after the process has been killed and all the used resources have been released; in particular, we were wondering what happens to the process' .exe file. Is there any guarantee that it will be unlocked after taskkill returns? - of course, theoretically it shouldn't be locked by any other process, this is the only case we're interested in.
views:
2950answers:
4Have a command line parameter like /Shutdown that the VB program will process.
MyApp.exe /Shutdown
/Shutdown parameter will find existing running instance of the app (using FindWindow API) and send a user message to the window requesting it to shutdown smoothly.
Taskkill should return only after the process has been terminated (as per comments below: use the /F flag to force termination of the program if it expects user input).
To learn more about it you can use Process explorer and see exactly when the process is terminated and also if anyone still has the .exe file open (Ctrl+F and the name of the exe) - but that shouldn't be the case.
If the process is killed, then the exe will be freed up for the update. As an alternative to using taskkill, you can use pskill from sysinternals, but taskkill should work great with the /IM parameter.
However, neither pskill or taskkill will not wait for the process to stop before returning control. So you would have to monitor the processes to make sure they're no longer running.
Also, and this would be my preferred solution, it's possible to deploy a vb6 app via click-once, which will automatically update the app with new releases. Check this article for details.
As for the resources opened by the process, it's possible that they might remain open (such as a sql connection), but most likely they will be successfully closed. You'll only be able to know for sure by monitoring what happens by testing out taskkill on the process.
Hope that helps.
I do this, by letting the app itself check for updates. If there are, then the app downloads them in a temporary place. After that it will start a (.js) script and exits the app. This script will wait for the process to close (sleep), copy the updates and start the app again.
This way you have far less logic in the script, and you can do your stuff in an environment you have more tools available.