Solved

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

Posted on 2002-04-26
4
233 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks, I'll give it a whirl and get right back.
0
 

Author Comment

by:suz123
Comment Utility
Crazyman...who is not so crazy.

Works perfectly, thanks for the quick response.

Sue
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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

7 Experts available now in Live!

Get 1:1 Help Now