Solved

Auto app update using Internet download

Posted on 2003-11-18
13
840 Views
Last Modified: 2010-04-05
Hi there!!

I need help, I'm quite new with Delphi, so I need ALL the help I can get.

I've got an app, sitting on a user's PC 1000km away from, the user is not bright at all!!
I am tired of having to explain to her everytime how to update the manually, this is painful process, because I have to explain to her: Double-click on 'My Computer', double-click 'C:'.

So you get the picture. I need to automate this process by automatically downloading the updated version from a web location, then updating the app without any prompts whatsover.

Please, any help will be gladly appreciated.

Thanx.
0
Comment
Question by:rynoster
  • 6
  • 3
  • 2
  • +2
13 Comments
 

Expert Comment

by:Excessmind
ID: 9770069
Maybe not the smartest answer, but I would write another app that checks and downloads updates, and when the user isn't using the program, applies updates. I would put updates on FTP server also.
0
 

Author Comment

by:rynoster
ID: 9770118
Using another app is the way I'm planning to do it, I just need the code to do it...

Don't have an ftp server.
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 9770164
 uses
                      Wininet;

                    function DownloadURL(const aUrl: string): Boolean;
                    var
                      hSession: HINTERNET;
                      hService: HINTERNET;
                      lpBuffer: array[0..1024 + 1] of Char;
                      dwBytesRead: DWORD;
                    begin
                      Result := False;
                      // hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
                      hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

                      try
                        if Assigned(hSession) then
                        begin
                          hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);
                          if Assigned(hService) then
                            try
                              while True do
                              begin
                                dwBytesRead := 1024;
                                InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);
                                if dwBytesRead = 0 then break;
                                lpBuffer[dwBytesRead] := #0;
                                Form1.Memo1.Lines.Add(lpBuffer);
                              end;
                              Result := True;
                            finally
                              InternetCloseHandle(hService);
                            end;
                        end;
                      finally
                        InternetCloseHandle(hSession);
                      end;
                    end;

not tested but i assume it works.....

just upload your program as an exe, if you want zip then there's ways to solve that as well...
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:rynoster
ID: 9770226
Ran the code, doesn't work.

I stepped thru it, but when it gets here (the if)

hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);
if Assigned(hService) then (not true),

so the rest of the code does not run...
0
 
LVL 17

Accepted Solution

by:
geobul earned 250 total points
ID: 9770433
Hi,

Try this (requires Windows 95 and IE 3.0 as a minimum):

uses URLMon;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if URLDownloadToFile(nil, 'http://www.yoursite.com/app.exe', 'c:\NewApp.exe', 0, nil) <> 0 then
    MessageBox(Handle, 'Cannott download the file.', PChar(Application.Title), MB_ICONERROR or MB_OK);
end;

Regards, Geo
0
 
LVL 5

Expert Comment

by:Gwena
ID: 9775612
A while back I wrote a little demo for a guy that wanted his delphi
program to update live from a new version on his website.

It works well and is really simple... the user does not need to know
how to do anything except be on the internet and click a button.

The exe just changes into the new version... the user does not
have to save a file or restart the program or anything...

here is the old demo... please right-click the link and choose
'save target as' because geocities does not allow direct external
links to files.

It includes a compiled exe so you can quickly test it by just adding exemod
to any delphi app and recompiling it... then placing it onto your website..easy :-)

http://www.geocities.com/gacarpenter386/LiveUpdate.zip

here is the readme from this demo
========================================
This demo uses the freeware Synapse lib internet code
to get the new exe from your website.....you can use any code
you wish instead... just so long as it can get a file and place
it into a stream.

Just place any delphi exe that has been compiled with the
ExeMod.pas unit included onto your website and then type the
url into the edit box on the form... when you click the
[update exe from url below] button the program will grab
the new exe from your site and place it into a memstream
and swap the new version for the old version... this may take
a few moments so be patient... the button will stay depressed
while the update is in progress..

I included a button to update the exe from a local file... this is
for testing purposes and works identically to the url method except
the new exe is on your local hd.  Just select the exe you wish to swap
in in place of the original and it will exchange and come up running
very quickly :-)

Appologies for the crudity of this demo... I was in a hurry.
also I did not get to test the url method as I have no web space
where I can place an exe to test with... Geocities does not allow
for direct lnking to files :-(  but it should work OK...
0
 

Author Comment

by:rynoster
ID: 9776641
Hi Gwena

First off, thanx ALOT for the cool demo. This works great, the only problem is that the exe I need to update is a VB app. So what I need is something that can just download from the net(without any prompts). Then overwrite the EXE file currently in use.

This will be a seperate app, and one of the conditions will be that the VB app must be closed before this one can run.

Thanx.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 9776968
Hi :-)

Ok... I'm clueless about VB so I can't help out with your problem...good luck!
0
 

Author Comment

by:rynoster
ID: 9777014
I got the following code from scalabium, but it only download an htm and puts the source in the memo box...

begin
  Memo1.Lines.Text := DownloadFile('http://www.scalabium.com/sme/index.htm')
end;


uses WinInet;

function DownloadFile(const Url: string): string;
var
  NetHandle: HINTERNET;
  UrlHandle: HINTERNET;
  Buffer: array[0..1024] of Char;
  BytesRead: dWord;
begin
  Result := '';
  NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

  if Assigned(NetHandle) then
  begin
    UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);

    if Assigned(UrlHandle) then
      { UrlHandle valid? Proceed with download }
    begin
      FillChar(Buffer, SizeOf(Buffer), 0);
      repeat
        Result := Result + Buffer;
        FillChar(Buffer, SizeOf(Buffer), 0);
        InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
      until BytesRead = 0;
      InternetCloseHandle(UrlHandle);
    end
    else
      { UrlHandle is not valid. Raise an exception. }
      raise Exception.CreateFmt('Cannot open URL %s', [Url]);

    InternetCloseHandle(NetHandle);
  end
  else
    { NetHandle is not valid. Raise an exception }
    raise Exception.Create('Unable to initialize Wininet');
end;
0
 
LVL 17

Expert Comment

by:geobul
ID: 9777033
rynoster, have you tried my proposal?
0
 

Author Comment

by:rynoster
ID: 9777046
Oh yes, I forgot.

It's looking for the function/procedure 'URLDownloadFile', it's not an internal Delphi function.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9777072
It's WinAPI function defined in URLMon unit. The same applies for InternetOpen, InternetOpenUrl, InternetReadFile and InternetCloseHandle functions defined in WinInet unit. They are not internal Delphi functions also.
0
 

Author Comment

by:rynoster
ID: 9777125
Thanks to geobul.

I forgot to put in the 'uses URLMon' ...

Thanks to all the other guys who helped.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question