DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Application updates itself


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!
Generated 20:01:39 on Oct 24, 2020