Replacing A Running Executable?
-
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
-
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
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
-
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
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
-
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
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