suz123
asked on
How to replace currently running EXE with EXE from web site?
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
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_
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I'll give it a whirl and get right back.
ASKER
Crazyman...who is not so crazy.
Works perfectly, thanks for the quick response.
Sue
Works perfectly, thanks for the quick response.
Sue
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.