Learn how to a build a cloud-first strategyRegister Now

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

How to replace a runing exe file?

I am writing a program, it need to upgrade very often,
So what I want to do is:
When my new program runing, it will check my website, if a new version available, then download and replace itself.
How to do it? I mean how to replace a exe file itself when it is runing?

Thanks

Chiwan
0
chiwan
Asked:
chiwan
  • 9
  • 8
  • 3
  • +7
1 Solution
 
Tomas Helgi JohannssonCommented:
listening....
0
 
gemartiCommented:
I wonder if you would be better off with a base application (the exe) that uses dll's for most of it's work.
Its probably easier to update a dll than it is a exe!

0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

I think you are
talking about the auto-update, so I wish these links be helpful for you

look at this article, "Get File From the Net"
http://delphi.about.com/compute/delphi/library/weekly/aa013001a.htm

TWEBUPDATE
www.tmssoftware.com

http://www.torry.net/tools_webupgarde.htm
http://www.npsnet.com/waletzky/TCynthesisAppUpdate.html

If you know some vb code, there's a link
Make programs with Internet Auto-Update Support
http://www.planet-source-code.com/xq/ASP/txtCodeId.7663/lngWId.1/qx/vb/scripts/ShowCode.htm

Best regards
Mohammed Nasman
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
JaymolCommented:
This kind of procedure will work....

You need to read parameters when the program is run, whatever version.

Make the old version download the new version (with a new name) and run it with a parameter of '/R' (R for Replace, for example), and then close.

The new version receives the '/R' and deletes the old version.  It then copies itself so that there is a copy of the new version, but with the same name as the old version.  It then runs the new version, with a '/U' parameter (U for update, for example) and closes.

When the program runs with a '/U' parameter, it simply deletes the other executable.

It's a bit messy, but I've written apps that write data directly within themselves using this kind of technique.

The only other thing is to have a seperate exe that runs the main app.  This can check for a newer version before running the existing and either replace the old one if there's a newer one, or simply run it if not.

Again, not a brilliant idea, but it does do what you've asked, and it's what I'd do.  Sometimes the theory behind the code is more important than the code.

Good luck,

John.
0
 
raidosCommented:

Also (in NT environments, dont know about Win9x) your able to move or rename a running file, but that is basically the same procedure as Jaymol has described.

//raidos
0
 
geobulCommented:
Hi,
Another way is to have two exes. The first one checks for a new version of the second exe, downloads it if any and then runs the second exe.

Regards, Geo
0
 
geobulCommented:
Oops, I've duplicated Jaymol's words.
Jaymol, I'm sorry.

Regards, Geo
0
 
JaymolCommented:
Heh.  Cheeky!

John.
0
 
geobulCommented:
I made an attempt to be polite.

Regards, Geo
0
 
YevgenCommented:
I think that the best way is to put anything you want to update in a dll and if it's being used in the middle of the replacement then load the DLL dynamically and while updating just unload it for the duration of the process...

GL
  Yevgeni...
0
 
GwenaCommented:
 You actually can replace an exe as it runs... but it is too dangerous to use except if the program is on a floppy...the technique involves writing to disk sectors directly and windoze is just too flakey and can't be relied upon to keep it's grubby hands away from the disk while your performing this sort of disk surgery..
  There are other ways to make it 'appear' that you are altering an exe as it runs when actually what you are doing is altering the exe and writing new versions to disk that then handle the file deletes needed to end up with a new exe that is running and has the same name that the old one had....I have a demo of this sort of strange dance up on my web site   http://www.codearchive.com/~gac/SelfMod.exe
http://www.codearchive.com/~gac/SelfMod.zip
http://www.codearchive.com/~gac/readme.html

This code might give you some ideas (usefull and otherwise :-)
Just alter it a bit and you can modify your exe or even replace it with a totally new one -- all seemingly as it runs.

0
 
GwenaCommented:
Oh.. the zip file above has the source code :-)

And remember that you should have your users only download the parts of the new version that have changed from the old version... usually a very small amount of data.. no need to send the delphi runtime stuff over and over since the exe on the users machine already has all that...
0
 
JaymolCommented:
Gwena,

After looking at your stuff on your site, I thought you might be interested in this...

   http://www.geocities.com/jaymol

Have a look at the TNoCopy component.  You might like it.

John.
0
 
GwenaCommented:
Hi Jaymol :-)
  Thanks.. I will go look at your site
0
 
GwenaCommented:
Jaymol...
I can't seem to load your page in.. it just hangs as it loads that component console... do you have a direct link to some of your files?  :-)
0
 
JaymolCommented:
Gwen, try this...

  http://www.geocities.com/jaymol/zipped/nocopy.zip

Thanks,

John.
0
 
JaymolCommented:
Sorry, but if you left-click it it doesn't work.  Right-click and do "save as" and it's fine!

I'm not too sure about whether or not I should have this page on Geocities!

John.
0
 
GwenaCommented:
Hi Jaymol :-)
  Geocities is really lame... I had a site there but they changed the rules and I could no longer upload exe. files ... plus I could no longer put links to my files on other web sites... to download a file the user has to be at your site on Geocities :-(

I will try again to dl your file :-)
0
 
GwenaCommented:
Hey that looks really interesting Jaymol... I just read the readme file... this is the same strange sort of software that I like to write :-)  

I tend to write software that only stores info inside it's own exe file... no ini or registry stuff for me...and I enjoy stuff like self modifying exe's, compression, encryption, copy protection...etc :-)

0
 
JaymolCommented:
Shall we do another thread if we wish to discuss this kind of thing?
0
 
GwenaCommented:
Hi Jaymol :-)
  I have a thread about activation url for D6 personal...it's a 0 point Q... I guess we could waste space over there :-)

I just posted a Delphi test exe that I'm using to work out the bugs in a tool I'm building... It can add a teeny delphi exe to anyone elses exe... the tiny stub program runs first...then the original... a way to add new functionality or whatever to existing exe's...it's a fully functional GUI delphi app in 19kb... altho it won't do much unless attached to an exe that has had the PE altered a bit... but you might be interested in seeing it cause it's so tiny :-)
http://www.codearchive.com/~gac/dtes.exe
0
 
chiwanAuthor Commented:
Gwena
  I have no rights to access the files, could you kindly give me right?

Thanks

Chiwan
0
 
GwenaCommented:
Hi chiwan :-)

 My site seems to be missing from the server it was on? I have sent an email to the site admin asking what's up... I hope it will be back on soonest ....
0
 
JaymolCommented:
Hi Gwen - Sorry, I've been away for a while.

I'd like to see your GUI app but I too have problems downloading so I'll get it as soon as it's available.  (It sounds like a "self-spreading" application I made once, but never found a practical non-virus like use for it.)

Let me know when your site's up and running again.

Thanks,

John.
0
 
AleqCommented:
Also you could deploy small app (2), and terminte yourself(1). That small app (2) waits for (1) termination, after that it deletes the (1), replaces (1) with new one (1').
Than it starts (1') with special firsttime parameter and closes itself (2). (1') according to special parameter deletes (2).

Bit messy, but will work :)

regards
  Aleq
0
 
JaymolCommented:
That's already been said, a long time ago Aleq.

John.
0
 
GwenaCommented:
Hi :-)
  I have temporarily moved my site back to geocities... the server where I did have it was attacked by some stupid hacker and they lost all the files or something... I'm still trying to get all my files together and up at the geo site...
http://delphi.does.it

There is a small 20kb delphi exe called file-combiner at the site it's a good example of how small a delphi exe can be.. I used all the tricks including re-aligning the PE,replacing the VCL, exe compression..etc   the selfmod program is up there. :-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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