Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application (service) self-upgrade?

Tags:

c#

.net

.net-4.0

I'm developing a .NET4-based application in C# which runs as a windows service.

I'd like this application to be able to upgrade itself when instructed to do so by a web-service that it connects to periodically. Is there an accepted way to accomplish this? Is it even possible?

The way I'm thinking of it is something like this:

  1. The windows service (.exe) code downloads its replacement and supporting DLLs as a zip and extracts them to a temporary directory. The zip also includes a small "upgrader" executable or script.
  2. The service forks a child process to run the upgrader, passing the destination directory and any other required information on the command-line
  3. The service shuts down
  4. The upgrader process waits for the service to stop completely, then moves the necessary files (new .exe, DLLs) into the final installation directory, replacing the old file(s)
  5. The upgrader restarts the windows service, which spawns the (upgraded) .exe and quits once it starts

Would this work? You may detect from my terminology and approach that I'm from a UNIX background and not a windows background. I've made this approach work on UNIX, but I have no idea what sort of windows gotchas may exist...

UPDATE: My main motivation for this question is around the technical feasibility of a self-updating .NET application (how to do an in-place replacement of .DLLs, etc). As pointed out in the comments, there are a host of other considerations involved in implementing a feature like this, in particular security concerns around verifying the new software components being applied are in fact legitimate. These are also important, but not specific to .NET or Windows (imo). Comments on these areas are welcome of course, but they are not my primary concern at this time...

like image 677
Kris Pruden Avatar asked Jan 21 '11 19:01

Kris Pruden


1 Answers

Your approach is certainly reasonable, but unless you run under the LocalSystem account (not recommended!) you don't have permissions to write to your application folder or to start/stop your own service. Even if you run under the user's account, you might have problems because of UAC although I am not sure of this. Anyway running under the user's account is not good since it requires the user to enter the account password and has additional complications arising from password change, lockout etc. You will have to set ACLs on both from your installer, which will have to run elevated anyway to install a service.

like image 118
Anton Tykhyy Avatar answered Nov 04 '22 07:11

Anton Tykhyy