Solved

How to replace currently running EXE with EXE from web site?

Posted on 2002-04-26
4
242 Views
Last Modified: 2010-05-02
The following code downloads the latest program release from our web site.  The problem is, I need to download the currently running EXE file...therefore it needs to download and replace itself.  

I've renamed the file at the web site to program.ex_ and downloading that file to the current folder works OK.

QUESTION...
How do I replace the running EXE with the revised EX_ once the download is complete and the program is still running.

CODE...
Private Declare Function URLDownloadToFile Lib "urlmon"_ Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal_ szURL As String, ByVal szFileName As String, ByVal_ dwReserved As Long, ByVal lpfnCB As Long) As Long


If getUpdate = 1 Then
    OKToDownload = MsgBox("Download latest program_ update ?", vbOKCancel)
    If vbOK Then
       If SaveURL_("http://www.somewhere.com/downloads/program.ex_", "c:\programDir\program.ex_) Then MsgBox "Download complete!"
    Else
       MsgBox "Download cancelled"
    End If
 End If
End Sub

Public Function SaveURL(ByVal sURL As String, ByVal_ sFileName As String) As Boolean
   sfile = App.Path & "\program.ex_"
   SaveURL = URLDownloadToFile(0&, sURL, sfile, 0, 0)
End Function
0
Comment
Question by:suz123
[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
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 6970914
I have written an autoupgrader program that does just this.
The thing to do is, rename the current running file(you can do this but you cant delete it) then download the new one, then end your exe and start up the new one, the new one then deletes the old one.
0
 
LVL 13

Accepted Solution

by:
crazyman earned 250 total points
ID: 6970922
Something like

If getUpdate = 1 Then
   OKToDownload = MsgBox("Download latest program_ update ?", vbOKCancel)
   If vbOK Then
      If SaveURL_("http://www.somewhere.com/downloads/program.ex_", "c:\programDir\program.exe)
Then
MsgBox "Download complete!"
'now end and start the new app
shell app.path & "\" & app.exename & ".exe"
unload me 'end here
   Else
      MsgBox "Download cancelled"
   End If
End If
End Sub

Public Function SaveURL(ByVal sURL As String, ByVal_ sFileName As String) As Boolean
  name app.path & "\" & app.exename & ".exe" as app.path & "\" & app.exename & ".old"
  sfile = App.Path & "\program.exe"
  SaveURL = URLDownloadToFile(0&, sURL, sfile, 0, 0)
End Function

then when you startup
' wait a few seconds to make sure that the old instance has quit, although its no big deal if we dont delete it

if len(dir(app.path & "\" & app.exename & ".old"))> 0 then
kill app.path & "\" & app.exename & ".old"
end if
0
 

Author Comment

by:suz123
ID: 6971419
Thanks, I'll give it a whirl and get right back.
0
 

Author Comment

by:suz123
ID: 6971583
Crazyman...who is not so crazy.

Works perfectly, thanks for the quick response.

Sue
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

695 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