Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (12)


Auto LiveUpdateFormat this article printer-friendly!Bookmark function is only available for registered users!
Auto LiveUpdate ur program from a ftp server
Product:
Delphi all versions
Category:
System
Skill Level:
Scoring:
Last Update:
02/19/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet InternetOpen InternetConnect NeedUpdate LiveUpdate FileIsInUse OpenProcess FtpGetFile
Times Scored:
3
Visits:
4987
Uploader: Smile xiao
Company:
Reference: N/A
 
Question/Problem/Abstract:
  When u get a file from web or sale a product to ur custom,
u have to update it urself when a new version fond,how can I
liveupdate it like Norton AntiVirus, Now, u can get some info
from here.
                            
3 k u
Answer:



first of all ,u need create a HInternet when it is created as following

constructor TULiveUpdate.Create(AOwner: TComponent);
var
  FINet: HInternet;
  // U need add WinINet to uses first
begin
  inherited;
  FINet := InternetOpen('WinINet1', 0, nil, nil, 0);
end;

then u need check if it is need update?

function TULiveUpdate.NeedUpdate(const FileName: string): Boolean;
var
  LFileS, SFileS: Integer;
  LFileT, SfileT: string;
begin
  // Link to ftp Server(u need declare FPath first)
  FftpHandle := InternetConnect(FINet, PChar(FPath), 0, '', '',
    Internet_Service_Ftp, 0, 255);
  if FftpHandle = nil then
    raise Exception.Create('Can''t link to ftp Server'+ FPath + '!');

  // Compare FileSize
  LFileS := GetFileSizeA(FileName);
  SFileS := GetFileSizeW(ExtractFileName(FileName));
  // Compare FileDate
  LFileT := GetFileDateTimeA(FileName);
  SFileT := GetFileDateTimeW(FileName);
  Result := (LFileS <> SFileS) or (LFileT <> SFileT);
end;

last , u can LiveUpdate now, If file is run , u need close it and down it, then open it again

function TULiveUpdate.LiveUpdate(const FileName: string): Boolean;
var
  FileIsRun: Boolean;
  hFile: THandle;
begin
  FileIsRun := FileIsInUse(FileName);
  // u need set TargetFile first
  if not FtpGetFile(FFTPHandle, PChar(FileName), PChar(TargetFile),
    False, File_Attribute_Normal, Ftp_Transfer_Type_Binary, 0) then
    RaiselastOSError;
  if FileIsRun then
  begin
    // If file is run, delete it and open a new process to open the Lasted file
    DeleteMe(FileName);  
    hFile := OpenProcess(1, False, FileProcessID);
    if SameText(FileName, ExtractFileName(ParamStr(0))) then
      ShellExecute(Application.Handle, '', PChar(FileName), nil, nil, 1);
    TerminateProcess(hFile, 0);
  end;
end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Application Maximazed
    shahram Rostami (Oct 17 2009 4:39PM)

I have Two exe, Exe1 and Exe2, I run Exe1 and minimazed to taskbar, Runing Exe2, I want Maximazed Exe1 by Exe2 with click button on Exe2.
Plz help me,
Respond

Very good
    Alejandro Castro (Oct 2 2004 2:38AM)

I am working with your code many days ago and it works fine !!
What about HTTP? Do you know the way to LiveUpate with HTTP?
Respond

attach a demo
    carol paquet (Jan 4 2004 6:52PM)

It can be good to attach a demo with your article.
So all the people can see how this code really work.
sorry my english is bad.
Respond

Where do I find the Unit
    Bjarne Winkler (Mar 12 2003 6:45PM)

Where do I find the Unit that declares "InternetOpen", "InternetConnect", "FileIsInUse", and "FtpGetFile"
-Thanks
Respond

RE: Where do I find the Unit
Smile xiao (Mar 13 2003 1:56AM)

all these files r in Unit "WinINet ", I have add this info on component was created as flowing..

constructor TULiveUpdate.Create(AOwner: TComponent);
var
  FINet: HInternet;
  // U need add WinINet to uses first

Respond

Good
    Bean (Feb 21 2003 1:58AM)

This article is good.
Can author give me a Demo.
Thanks.
Respond

RE: Good
Smile xiao (Feb 21 2003 2:22AM)

Hi,U can use a MSN Messenger link me.
Thank U.
Respond

RE: RE: Good
Juan Pablo (Jun 17 2003 6:53AM)

Hello, do you have a sample for live update? My MSN is mendes74@hotmail.com

Thanks
Respond

RE: RE: RE: Good
Smile xiao (Jun 18 2003 2:59AM)

OK,I'll give u a demo
Respond

RE: RE: RE: RE: Good
John Edwards (Aug 31 2004 7:05AM)

Hi,  Could you please send a demo to me as well at target101@hotmail.com

Thanks..
Respond

RE: RE: RE: RE: RE: Good
Omark Saldaña (Jan 14 2005 6:10PM)

Hi, I would like a demo too at omarkpatricia@hotmail.com thanks.
Respond

RE: RE: RE: RE: RE: RE: Good
Cedric (Feb 17 2005 12:27PM)

Hello, I would like also a demo my msn is charpy@hotmail.com
I didn't find the Unit for GetFileSizeA
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Shkolnik
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)