Solved

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no 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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

730 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