How to replace a currently running exe..

Started by
5 comments, last by Zern 21 years, 2 months ago
Hello, I''ll get straight to the point, I created a patcher program that can update itself. I download the new executable to a file called "programname.ex_". My question is how do I in turn, have the currently running patcher, delete itself while renaming the "programname.ex_" to -> "programname.exe." My thoughts are to create an additional simple application that will replace all file extentions ( *.ex_ ) ( *.ba_ ) etc whatever I add to it, to *.exe *.bah. Start this simple application through a CreateProcess function. That is the only way I see fit, however is there a way to have an executable replace itself without firing up another application to do the deleting/renaming? Thanks in advanced. ~
Advertisement
MoveFileEx(..., ..., MOVEFILE_DELAY_UNTIL_REBOOT);


[edited by - niyaw on January 30, 2003 4:24:45 PM]
Self-Deleting Executables (http://freespace.virgin.net/james.brown7/tuts/selfdel.htm)
----------
crAzy

[edited by - Extrarius on January 30, 2003 4:28:47 PM]
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
quote:Original post by niyaw
MoveFileEx(..., ..., MOVEFILE_DELAY_UNTIL_REBOOT);


[edited by - niyaw on January 30, 2003 4:24:45 PM]



I seen that but noticed it only works on Win NT3.1 + and not Win95/98/ME. Also waiting until the system reboots to replace the file seems a bit annoying to have the user reboot just to have an updated client. However thanks for your time.



Extrarius, nice link. Thank you as well.


I believe creating a batch file is the best way to go about this. CreateProcess hiding the window using techniques provided by the link Extrarius gave to give the new batchprocess very low cpu priority, then have it replace the old files with the new .


Thanks again to both of you.

~
Hi there silly bear,
I did this using VB, but the same methods apply. What i did was check for a new *.exe version - if there was one, then rename the current exe old*.exe (you can rename an exe whilst running). Then, copy the new exe to the old exe''s folder and name it *.exe. Then send a message box to the user letting them know to restart the program (their shortcuts now point to the new version). Lastly, or firstly as the case may be, every time the program starts, it checks its folder for old*.exe and deletes it if found.

The only drawback to this method is that the user must restart the program.

Hope this fucking helps

aface
LOL, you could simply spawn the new application when finished, and unload yourself.. that way they don''t even have to manually do it . Good advice though, simply rename to an old.exe or whatever, and rename the game.ex_ file to game.exe, then spawn the new process (game.exe), then close itself. The game.exe file would check for old files, and delete them. Should work fine that way.
quote:Original post by Aface
Hi there silly bear,
I did this using VB, but the same methods apply. What i did was check for a new *.exe version - if there was one, then rename the current exe old*.exe (you can rename an exe whilst running). Then, copy the new exe to the old exe''s folder and name it *.exe. Then send a message box to the user letting them know to restart the program (their shortcuts now point to the new version). Lastly, or firstly as the case may be, every time the program starts, it checks its folder for old*.exe and deletes it if found.

The only drawback to this method is that the user must restart the program.

Hope this fucking helps

aface




LOL another idea that sounds good.

Ready4Dis - Yes, I am going to have it automated ( download the updated client/extra files - delete/rename to correct names, reload the new exe if found else no need to close the original until done updating ).


Thanks for the responces

This topic is closed to new replies.

Advertisement