Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-04-26
4
Medium Priority
?
245 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

618 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