[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 848
  • Last Modified:

Auto app update using Internet download

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
rynoster
Asked:
rynoster
  • 6
  • 3
  • 2
  • +2
1 Solution
 
ExcessmindCommented:
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
 
rynosterAuthor Commented:
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
 
craig_capelCommented:
 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rynosterAuthor Commented:
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
 
geobulCommented:
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
 
GwenaCommented:
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
 
rynosterAuthor Commented:
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
 
GwenaCommented:
Hi :-)

Ok... I'm clueless about VB so I can't help out with your problem...good luck!
0
 
rynosterAuthor Commented:
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
 
geobulCommented:
rynoster, have you tried my proposal?
0
 
rynosterAuthor Commented:
Oh yes, I forgot.

It's looking for the function/procedure 'URLDownloadFile', it's not an internal Delphi function.
0
 
geobulCommented:
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
 
rynosterAuthor Commented:
Thanks to geobul.

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

Thanks to all the other guys who helped.
0

Featured Post

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!

  • 6
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now