DelphiFAQ Home Search:

Application updates itself


comments1 comments. Current rating: 4 stars (1 votes). Leave comments and/ or rate it.


I want to allow my application to update itself. I run into a problem here when I try to copy the updated version of my executable over the one existing on the server. Windows will not let me if a client is running it.


I had to do the same task for SourceCoder's web edition. At least in Windows NT/ 2000, the following will work - (I think it does not work with Windows 95).
Let's assume that the name of your .EXE file is myApp.exe.

1) delete an old backup, if existing

2) rename the running EXE to *.exe.bak

3) copy the new EXE over

4) restart the application and close the existing one.

You can also use the WinNT/Win 2000 _MoveFile_ _API_ to delete the old version at the next reboot.

See the sample source code below.

procedure UpdateMyself;
  bakName : string;
  bakName := ChangeFileExt(Application.ExeName, '.old');
  if FileExist(bakName) then
  RenameFile (Application.ExeName, bakName);
  CopyFile('c:\downloads\' + Application.ExeName, Application.ExeName);
  // restart and shutdown old session
  WinExec(Application.ExeName, sw_ShowNormal);
You don't like the formatting? Check out SourceCoder then!
Content-type: text/html


2007-08-06, 15:14:33
from Finland  
your example is helpful, but I suppose it would be easier, to include an update check on the OnCreate event, then prompt the user for update, call a separate updater program, and go on with business as usual.
If the updater program needed to be updated first, the main application could handle this.

This way it would work, regardless of the OS.



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: