Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Self updating application

Hi

I would like to add a self updating feature to my application. E.g. there is a central version number held on the server. When a user opens abc.exe with an old version, abc.exe should update itself with the latest version available on the server.

I know copying files very well, so this is not a problem. More the challenge is to overwrite a file that's in use. Does anyone know how to do this?

Also, I know this is possible with a seperate batch file or updating program, which I would like to avoid.

Thanks

Jeremy
0
JezzaKashel
Asked:
JezzaKashel
  • 3
  • 3
  • 2
  • +3
1 Solution
 
Marv-inCommented:
updating the exe that is running could be bad - however if you stored your code in dll files you could drop the reference update the dll and relink it.
0
 
mlmccCommented:
We considered trying thsi but weren't allowed for a variety of reasons.

Basic method
User executes a small app that checks version
If version ok then
  Execute the program
else
  Update the program (copy new exe, do an update install)
  Execute program

mlmcc
0
 
larrysyCommented:
why not just end the current program from the program itself once as new version is detected

program itself checks the central server on every start for a new version
If version current then
  Execute the program
else
  open a webpage which will automatically download the new program from server
  end program
  if saving to the same directory, the browser will ask the user if he wants to overwrite

larrysy
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
trkcorpCommented:
I have done this by placing a simple text file on the server containing the new or current version along with the install - and upon start up (sub Main) I check this to see if I should update the program.  If so, I kick off the update and exit the program:
Sub Main()
Dim sVerChk as String

'I load frmSplash & check user ID & stuff 1st ... THEN

'Ver Update code
On Error GoTo SkipChk
If Dir$("\\SERVER\APP\ver.txt") <> "" Then
  Open "\\SERVER\APP\ver.txt" For Input As #1
  Input #1, sVerChk
  Close #1
  If sVerChk = "LOCKED" Then
    MsgBox "This application has been locked by the developer.  Maintenance is under way and the " & _
      "application is incompatible until it is completed.  Once completed, this lock will be rescinded" & _
      " and you will be allowed entry." & vbCrLf & vbCrLf & "Please try again later.  Thanks for your " & _
      "patience.", vbOKOnly + vbSystemModal, "Access Denied"
    Unload frmSplash  
    Exit Sub
  End If
  If sVerChk > App.Major & "." & App.Minor & "." & App.Revision Then
    If MsgBox("A new version of your program is available!" & vbCrLf & _
      "You must upgrade or exit.  If you are dialed in remotely via modem this action is not advised." & vbCrLf & _
      "Once you begin this process you must complete it or undesirable results may occur." & vbCrLf & _
      vbCrLf & "Do you wish to run setup now?", vbOKCancel + vbQuestion + vbSystemModal, "UPDATE AVAILABLE") _
      = vbCancel Then
      Unload frmSplash
      MsgBox "You will need to perform the update before you can run the application.", _
        vbOKOnly + vbInformation, "UPDATE AVAILABLE"
      Exit Sub
    End If
    MsgBox "Please take all defaults while executing the setup program.  Changing any defaults can cause " & _
      " unpredictable results on future upgrades." & vbCrLf & vbCrLf & "Thank You for your cooperation.", _
      vbOKOnly + vbInformation, "Setup Instructions"
    rtn = Shell("\\SERVER\APP\setup.exe", vbNormalFocus)
    Unload frmSplash
    Exit Sub  'Ends the current invocation of the program
  End If
End If
GoTo OKCont
SkipChk:
'Note that this code will allow the user to continue if the click OK instead of Cancel...
If MsgBox("Error: " & Err & " Desc: " & Err.Description & vbCrLf & "This occurred while attempting auto update." & _
  vbCrLf & vbCrLf & "( * If it is error 52, then you are not connected to the network or the path " & vbCrLf & _
  "\\SERVER\APP" & vbCrLf & "is not visible to your computer. * )", vbCritical + vbOKCancel + vbDefaultButton2, _
  "PROGRAM UPDATE ERROR") = vbCancel Then
  Unload frmSplash
  Exit Sub
End If
Err.Clear
OKCont:

' And we execute our program as usual from here on out...
This approach allows me to lock people out while I make database changes or do other maintenance as well.  The ver.txt file simply contains a string like "3.4.1".  I used the > to check this but be careful, you may want to use <> instead based upon how your revision numbers go. For example: "3.4.11"  is NOT > "3.4.9"...
0
 
JezzaKashelAuthor Commented:
Hi trkcorp

Thanks for your comments, this looks to be what I'm after.

From what I've seen of your approach, you are updating the current exe (e.g. abc.exe) by running the setup on the server via the command rtn = Shell("\\SERVER\APP\setup.exe", vbNormalFocus).

Does this not cause some problems because your setup program will overwrite the abc.exe that is currently running. Acutally due to user rights etc I was just going to have a batch file that would copy the exe from the server. Will this work also?

Thanks

Jeremy
0
 
trkcorpCommented:
    No problems; I kick off the install FROM the server, not ON it, and then immediately exit the application.
(Exit Sub  'Ends the current invocation of the program)  *IMPORTANT* When your start up object is Sub Main exiting that sub effectively ends the program...
    The install initialization has a splash and has to gather its "list" & all - it stops and asks questions just like any install normally does and it won't even attempt to overwrite the exe until you get to the real install part... The initiating exe is exited before install has a chance to even think about being in conflict.
    You are more likely to run into a conflict trying to copy the exe from within itself, but if you place a slight pause in the .bat file to allow a complete exit from the calling program before the copy begins you can probably avoid that conflict.  
    Personally, I would prefer the install (setup.exe) approach, although it is more cumbersome for the user, it is more professional looking and if you are making ongoing enhancements and bug fixes you will eventually most likely need to run a full install at some point anyhow.
   
     
0
 
JezzaKashelAuthor Commented:
Hi trkcorp

Thanks for that. I'll have to take the exe approach, as the users Pcs are seriously locked down with regards to permissions. They have no chance of registering Dlls etc.

Just one question, how do I put the pause in the batch file without the user having to click to continue. Is there not the equivalent of the vb wait command?

Thanks

Jeremy
0
 
jimbobmcgeeCommented:
You can emulate a sleep-style command in a batch file by using PING.  Since PINGING takes a bit of time, use:

      PING localhost -n 10 > NULL

to ping your own machine 10 times.  >NULL suppresses screen output.

Not the nicest workaround, though...

HTH

J.
0
 
Marv-inCommented:
jimbobmcgee - nice trick =]

i know the microsoft resource kit for the 2003 server has a sleep command.
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

0
 
trkcorpCommented:
The above suggestions are good or you could write a little VB interface to do the copy instead of using bat files.  The VB interface could take a second or two allowing ample time for the app to exit, and then even allow the user to cancel or go ahead if you so desired.  You could provide status on the copy operation and issue a message when complete.  You could even sort of reverse engineer using the logic above to allow the user to start their new version of the program (then end the copy pgm) if you want.  This little VB interface could also perform other tasks you may dream up as you go along...
Good luck!
0
 
JezzaKashelAuthor Commented:
Thanks for all the comments.

In fact, the sleep command was not necessary in the batch file, the exe gets updated well with just the line:

copy "\\Server\abc.exe" "C:\Program Files\abc"

So all is good

Many thanks

Jeremy
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now