Replacing executable while running

  • Thread starter Thread starter paulo
  • Start date Start date
P

paulo

Hello,

I'm implementing an update system for our Windows Forms application
which has some requirements not provided by current solutions, including
ClickOnce. My only trouble now is how to replace the executable
(running) file. Is there any way to do this without any external process?
Thanks in advance for any help given.

Regards,
paulo
 
You could try to rename the EXE file from the application itself.

With System.Deployment you have also some customization available if you
have the appropriate events fitting your needs...
 
Hello Patrice and thank you for your reply.

I just used "File.Replace" to replace the running executable file and
did an "Application.Restart" and it worked very well. Is this safe? I
tried to delete the executable file in Windows Explorer while running
and it doesn't allow me to do that, so why does "File.Replace" works?
Can I use it without any fears?

Regards,
paulo
 
Don't know but I remembered to have done or seen this long ago. The only
problem I could think of would be if loading something from the exe file
(even though I believe it's perhaps not a problem as the system likely uses
a handle on the file ?).

Might be well why Replace works while Deleting likely won't (the file is
just renamed i.e. the system perhaps still have a handle on the "old" file
and just keep working opposed to deleting the file while in use that really
cuts your own branch)
 
Hi Paulo,

Thank you for posting.

The File.Replace method replaces the contents of a specified file with the
contents of another file, deleting the original file, and creating a backup
of the replaced file.

The operation that this method performs is to modifty the contents of the
specified file without deleting it. So even if the file is opened, or
running if it is an exe file, the File.Replace method would execute
successfully. The new content of the replaced file won't reflect at once
in the current opened file or the running program. It is the next time the
file is opened or the program runs that the new content is showed.

This method is safe and you could use this method without any fear.

If you have any other questions, please don't hesitate to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Hello Jared,

Using File.Replace to replace the files and then calling
Application.Restart works just fine and everything is done inside the
running application.

Regards,
paulo
 
Hi Paulo,

You're welcome!

If you have any other questions, please don't hesitate to contact us. It is
always our pleasure to be of assistance.

Have a nice day!

Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Back
Top