Solved

Auto app update using Internet download

Posted on 2003-11-18
13
838 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
Comment Utility
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
Comment Utility
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
Comment Utility
 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
 

Author Comment

by:rynoster
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rynoster
Comment Utility
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
Comment Utility
Hi :-)

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

Author Comment

by:rynoster
Comment Utility
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
Comment Utility
rynoster, have you tried my proposal?
0
 

Author Comment

by:rynoster
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks to geobul.

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

Thanks to all the other guys who helped.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now