Self updating exe

  • Thread starter Thread starter John Bailo
  • Start date Start date
J

John Bailo

There's some articles about Smart Clients for .NET 2.0 but I am thinking
of a simple method to have a smart client I am writing update itself.

Question:

1) Say I create a web method that displays a version number

2) At start up, my client, wherever it is, tries to match the version number

3) If not, it wants to update itself.


So, my question is, is there away to get a windows application (exe)
which is already loaded, to copy a new version of itself across the
network, then shut down, and then load the new copy?

Can this be done with Reflection?
 
John,

You have the right idea, but to make this work you need to have a
slight shift in thinking.

I've done a couple of Smart Client applications and have used a loader
application that executes prior to the actual application. This loader
calls a web service and presents a manifest (an XML document listing
all the assemblies and their related versions) to compare to a
server-side manifest which may have updated assembly versions ready for
download.

If new versions are found, the updater application copies the new
assemblies down to the application directory on the local machine. When
all updates are complete, the local manifest is updated and the updater
application launches the "real" application and shuts itself down.

Now, if you wanted to have an application check for updates while it's
running, you could use the same code that the updater uses while the
application is running. If new assemblies are detected on the server,
the application could notify the user and ask if they wanted to update
the application. If the user indicates "Yes," then the application
would launch the update application and shut itself down. It would have
the same basic effect of the user manually shutting the application
down and starting it back up. Then, once the updater application was
done downloading the new assemblies, it would launch the application
and kill itself again.

As I mentioned earlier, I've used this pattern on a couple of different
application and it works pretty well. I hope this answers your
question.

Thanks,
Denny Boynton
 
This looks perfect except in the system requirements it says:

"System Requirements

The Updater Application Block requires the following software:

* Windows XP Professional"


It's not clear if that means it can only be deployed on XP Pro, or if
that's what it needs to compile it.

My shop has a mix of XP Pro, Home, w2k server, w2p pro, 98 so I would
need something that could update on all these platforms.
 
I was thinking of another method.

Couldn't I use Reflection.Emit ?

If I could send a byte stream of the new version, and have the old
version Emit the assembly, then shutdown the first copy and then save
itself to the name of the *.exe on disk?

This way I only need one exe not a loader and an application.
 
John,

The Update Application block is an excellent way for looking at how
this process can work. I looked at it initially and what stopped me
from just using it was all the dependancies it has on the other
application blocks. In the end, it was faster and easier for me to use
the concepts exemplified in the Updater block and build my own
application specific to the environment to which the application would
be deployed.

Thanks,
Denny
 
It seems to necessitate a lot of additional layers and downloads to
accomplish something that can be done just as easily with your method.
 
Back
Top