The above does a couple of things. Here’s some more detail.
- Compares the currently running version to the version found in the downloaded file.
- If an update is available the user is prompted to upgrade (Yes/No buttons) – see the screenshot below this list for what the prompt looks like.
- If they click No, nothing else happens.
- If they click Yes the AppStart.exe process is started and the currently running executable is terminated gracefully with an exit code of 0 – Environment.Exit(0).
Now to the other part of the process – AppStart.exe. This small part of the project is important but relatively simple. The steps, from beginning to end, are as follows.
- Download the upgraded executable (in this case Countdown.exe) using a temporary file name.
- Delete the old executable.
- Rename the temporary downloaded executable to the same name as the old file.
- Run the new executable.
- Gracefully terminate AppStart.exe with an exit code of 0 – Environment.Exit(0).
In fact, the upgrade process is so simple, here is the entire code. 🙂 Note that it ALL runs in the form’s Load event! The method below has some extra stuff to make the process pretty like showing the user where the process is up to but you could make the entire process invisible by leaving this code out and hiding the form when the app starts if you wanted.
Remember that you’ll need to add the following code to the top of the main code file if aren’t going to fully-qualify the WebClient object.