Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Auto app update using Internet download

Posted on 2003-11-18
13
Medium Priority
?
846 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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