Writing a self-updating application correctly is not a trivial task. Most of the problems you mention in your question, such as files in use etc.
From trial and error I find that the best approach (roughly) is to:
- Create a system-wide event in the application using wait handles that can listen for requests to shutdown from another process.
- Package the application via an MSI installer.
- Use a bootstrap application in
%TEMP%
folder to send the signal to the first application, and start the MSI installer.
- The MSI will then handle all the other hard work of actually updating the application for you, dealing with file locks etc.
Unfortunately, the problem with self-updating apps is that unless you design all of this to work with v1 (and test it before release with a fake v1.1), then you'll find that you need features in the old version to help do the update to the new version.
If an MSI installer isn't an option, then a bootstrap application running in a temporary directory that can do the swapping, process termination etc. is a good way to start.
Depending on your application design, you may also need to ensure that the self-update process elevates itself on Windows Vista and later so that it can write to directories such as %PROGRAMFILES%
to do the file writes.