procedure UpdateMyself;
var
bakName : string;
begin
bakName := ChangeFileExt(Application.ExeName, '.old');
if FileExist(bakName) then
DeleteFile(bakName);
RenameFile (Application.ExeName, bakName);
CopyFile('c:\downloads\' + Application.ExeName, Application.ExeName);
// restart and shutdown old session
WinExec(Application.ExeName, sw_ShowNormal);
Application.Terminate;
end;