I have the need to deploy a program that can update itself. I came up with a rather simple strategy. When the program starts it downloads a file from the web, which contains the version number of the latest edition (this file is maintained manually, I though about extracting the version number but the site is deployed on Linux and it needs to be very fast in case many users download the program). If the number there matches the internal version (extracted from the version information), that's OK. If not, I suggest the user to download the new version.

If the user agrees, I get the new version, save it as s different filename, run an "updater" application (as the program executable file is locked while the program is running) and terminate the current program (remember this is before the program created its main form):

      if MessageDlg (
'A new version of YYY is available. '...
mtConfirmation, mbYesNo, 0) = idYes then
begin
// download new version
filestream := TFileStream.Create (Application.ExeName + '_update', fmCreate);
Http.Get('http://www.xmltypist.com/download/YYY.exe', filestream);
filestream.Free;

WinExec ('UpdateYYY.exe', 0);
Application.ShowMainForm := False;
Application.Terminate;
end;

The UpdateYYY program is a non visual program that waits a little time (for the main program to actually terminate), copies the current executable to a backup file, moves the _update version in place, and executes the new main program. There is a little extra code I'm adding for to comply with Vista protection, but more or less it works.

Now I know I have to update this strategy a little, as I might need to update other files like DLLs that are statically bound, so again they can be replaced only by stopping the program. I though about using the installer (InstallAware in particular) to manage the updates, but overall I'd rather use a manual approach as depicted above.

How to you mange automatic updates of Delphi programs? Any suggestions or ideas? Do you know of a better approach? I'm all ears... and will soon let you know about this "soon-to-be-free-for-all" program I resumed working on...