views:

60

answers:

3

I'm trying to create an auto-updating app using Winforms. I can't use click-once or the updater block because the app needs to run on Mono also.

Once I download the new exe file from a webservice, is it possible to unlock the running exe file, replace it, and restart the app?

+2  A: 

No. You can't replace a running executable. You'll get an access violation.

The best option is to create a separate, small executable that does the replacement for you. Your application can call it, shut itself down, and the second executable can do the download/replace/relaunch for you.

This also has the advantage of allowing you to setup the "updated" to require elevated permissions, which may be required, depending on where the application you're replacing is installed.

Reed Copsey
A: 

I wouldn't do that (It won't work; you'll get an access violation). Instead you could:

  • Download another executable to somewhere on the user's pc (Temporary Documents or your app's folder, for example) then let that update your program.
  • After the update has finished, start up your updated program and pass the location of the updater to it, where your updated app can now delete it. Or just leave the updater where it is.
Callum Rogers
A: 

Check out how ClickOnce can be used in such scenarios.

Lex Li