Self Upgrade

Overwrite exe file itself to get upgraded


Not like a jar file, when a generated exe file is running, it cannot be overwritten. The idea to upgrade it within program by overwriting itself will not work. So, we need to use an alternative way to overwrite the running exe file within program.

The new class 'SelfUpgrade' in integrate API is for that purpose. The solution is encapsulated in the class, so we will introduce the usage first, then if you're interested, take a look at the solution.

Usage of SelfUpgrade

Put the source file '' into your source code directory. The class contains following methods:

public class SelfUpgrade {

     * Call install() at beginning of main()
    public static void install();

     * Detect new version by yourself in your java program,
     * download new version of exe file by yourself in your java program,
     * and save as filename(), then call execAndExit(finename());
    public static String filename();
    public static void execAndExit(String exefilename);


To overwrite exe file itself with a newer version of exe file:

  1. Save the newer version of exe file as 'SelfUpgrade.filename()'
  2. Call 'SelfUpgrade.execAndExit(SelfUpgrade.filename())'
  3. At the beginning of main(), call 'SelfUpgrade.install()' to really overwrite the running exe file.

Then the exe file will be updated.

Ideas of Solution

The main idea is to use another exe file as a temporary exe file. For example, there is a "demo.exe" is running and going to upgrade itself:

  1. "demo.exe" downloads the new version of exe file and saves it as a temporary filename "demo.exe.selfupgrade.exe".
  2. "demo.exe" calls 'SelfUpgrade.execAndExit()' to start "demo.exe.selfupgrade.exe", and "demo.exe" itself exits.
  3. When "demo.exe.selfupgrade.exe" starts and calls 'install()', it copies itself to "demo.exe", and call "demo.exe", then itself exits.
  4. When "demo.exe"(now it is upgraded) starts and calls 'install()', it deletes temp file "demo.exe.upgrade.exe".

The Self Upgrade completes.

See Also

  • Integrate API - 20K, API library to integrate with generated exe.

Add new comment