Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Replacing A Running Executable?

Replacing A Running Executable?

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminalgorithmshelptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nde_plume
    wrote on last edited by
    #1

    Does anyone know of a good way to replace a running executable file. Specifically, I have a piece of client software that I want to be able to update from the server. I need some sort of mechanism to replace the executable file while it is running. Obviously, I can readily download a new binary from the server without any problems, the question is how to get it executing? I had considered the idea of using a little proxy program with this algorithm: If filename2 is newer than filename1 then copy filename2 to filename1 end if execute filename1 Using an algorithm like that, filename1 is the standard executable file for my software, and an update is simply copied to filename 2. That means that next time the proxy program is run (which is always when you start the software) it auto updates. However, there are a few problems with this, such as the hit on startup, and the fact that you have to restart before getting the new updated software. Does anyone have a better approach to this? (Oh, BTW, excuse the VB in the algorithm above, I switch between so often that I forget where I am sometimes!!) Thanks for your help

    A A T 3 Replies Last reply
    0
    • N nde_plume

      Does anyone know of a good way to replace a running executable file. Specifically, I have a piece of client software that I want to be able to update from the server. I need some sort of mechanism to replace the executable file while it is running. Obviously, I can readily download a new binary from the server without any problems, the question is how to get it executing? I had considered the idea of using a little proxy program with this algorithm: If filename2 is newer than filename1 then copy filename2 to filename1 end if execute filename1 Using an algorithm like that, filename1 is the standard executable file for my software, and an update is simply copied to filename 2. That means that next time the proxy program is run (which is always when you start the software) it auto updates. However, there are a few problems with this, such as the hit on startup, and the fact that you have to restart before getting the new updated software. Does anyone have a better approach to this? (Oh, BTW, excuse the VB in the algorithm above, I switch between so often that I forget where I am sometimes!!) Thanks for your help

      A Offline
      A Offline
      Abbas_Riazi
      wrote on last edited by
      #2

      Hi, Like you I want to write an application to transfer a file on the net (or LAN). Is it possible to share your file transfer code to me? Thanks a lot, A. Riazi

      1 Reply Last reply
      0
      • N nde_plume

        Does anyone know of a good way to replace a running executable file. Specifically, I have a piece of client software that I want to be able to update from the server. I need some sort of mechanism to replace the executable file while it is running. Obviously, I can readily download a new binary from the server without any problems, the question is how to get it executing? I had considered the idea of using a little proxy program with this algorithm: If filename2 is newer than filename1 then copy filename2 to filename1 end if execute filename1 Using an algorithm like that, filename1 is the standard executable file for my software, and an update is simply copied to filename 2. That means that next time the proxy program is run (which is always when you start the software) it auto updates. However, there are a few problems with this, such as the hit on startup, and the fact that you have to restart before getting the new updated software. Does anyone have a better approach to this? (Oh, BTW, excuse the VB in the algorithm above, I switch between so often that I forget where I am sometimes!!) Thanks for your help

        A Offline
        A Offline
        Alvaro Mendez
        wrote on last edited by
        #3

        This is what I would do: 1. When the program (filename1) starts up, it checks if there's a newer version of itself available. 2. If so, it runs another small (invisible) program, passing it the process ID (GetCurrentProcessId) as a command-line parameter. Then it exits. 3. The small program then takes the process ID and retrieves the process handle for it (OpenProcess). 4. It then waits for the process to finish (WaitForSingleObject). 5. Once that happens, it copies the new version of the program (filename2), runs it, and exits. Regards, Alvaro


        All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain

        1 Reply Last reply
        0
        • N nde_plume

          Does anyone know of a good way to replace a running executable file. Specifically, I have a piece of client software that I want to be able to update from the server. I need some sort of mechanism to replace the executable file while it is running. Obviously, I can readily download a new binary from the server without any problems, the question is how to get it executing? I had considered the idea of using a little proxy program with this algorithm: If filename2 is newer than filename1 then copy filename2 to filename1 end if execute filename1 Using an algorithm like that, filename1 is the standard executable file for my software, and an update is simply copied to filename 2. That means that next time the proxy program is run (which is always when you start the software) it auto updates. However, there are a few problems with this, such as the hit on startup, and the fact that you have to restart before getting the new updated software. Does anyone have a better approach to this? (Oh, BTW, excuse the VB in the algorithm above, I switch between so often that I forget where I am sometimes!!) Thanks for your help

          T Offline
          T Offline
          Todd Smith
          wrote on last edited by
          #4

          There's multiple ways to do this: 1. There's a wait for reboot option in MoveFileEx MoveFileEx(src, dst, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); 2. Download the update exe and run it. The update exe can post a message to the current application telling it to quit. Once it has exited then you can replace it with the update. Todd Smith

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups