Solved

How to replace a runing exe file?

Posted on 2001-08-02
27
374 Views
Last Modified: 2011-10-03
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
Comment
Question by:chiwan
  • 9
  • 8
  • 3
  • +7
27 Comments
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 6344053
listening....
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6344214
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
 
LVL 22

Accepted Solution

by:
mnasman earned 50 total points
ID: 6344231
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6344237
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
 
LVL 3

Expert Comment

by:raidos
ID: 6344295

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
 
LVL 17

Expert Comment

by:geobul
ID: 6344808
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
 
LVL 17

Expert Comment

by:geobul
ID: 6344827
Oops, I've duplicated Jaymol's words.
Jaymol, I'm sorry.

Regards, Geo
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6344834
Heh.  Cheeky!

John.
0
 
LVL 17

Expert Comment

by:geobul
ID: 6346212
I made an attempt to be polite.

Regards, Geo
0
 

Expert Comment

by:Yevgen
ID: 6346597
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
 
LVL 5

Expert Comment

by:Gwena
ID: 6346638
 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
 
LVL 5

Expert Comment

by:Gwena
ID: 6346657
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6347649
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Expert Comment

by:Gwena
ID: 6349003
Hi Jaymol :-)
  Thanks.. I will go look at your site
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6349619
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6354885
Gwen, try this...

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

Thanks,

John.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6354887
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
 
LVL 5

Expert Comment

by:Gwena
ID: 6354959
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
 
LVL 5

Expert Comment

by:Gwena
ID: 6354983
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6354985
Shall we do another thread if we wish to discuss this kind of thing?
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6357790
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
 

Author Comment

by:chiwan
ID: 6387034
Gwena
  I have no rights to access the files, could you kindly give me right?

Thanks

Chiwan
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6387128
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6387185
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
 

Expert Comment

by:Aleq
ID: 6409250
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
 
LVL 6

Expert Comment

by:Jaymol
ID: 6409254
That's already been said, a long time ago Aleq.

John.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6410787
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now