Solved

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

Posted on 2002-04-26
4
237 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

816 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

9 Experts available now in Live!

Get 1:1 Help Now