0

I have a windows service (C#, with ability to install itself). I also have an installer package the can update the windows service. This updater is currently run manually. The (NSIS) installer/updater runs net stop myService to stop the service, then does the install/update and then net start myService.

My goal is to have the service update itself in some way. This excellent question, and its highest rated answer lists all the possible ways one could probably approach the problem.

It seems to me the simplest, best option is to have the service Proces.Start() the installer. The only minor caveat, is that the installer needs to know how to stop the service for the duration of the upgrade - which my installer already has.

I've heard rumors that this is problematic, but in my testing, things seem to be working well. What, if any, are the known issues that will cause problems with this?

Community
  • 1
  • 1
davidpricedev
  • 2,107
  • 2
  • 20
  • 34
  • 1
    There is one more alternative: use PendingFileRenameOperations. You can provide the updated files and have them replace the old ones on next boot. – Marged Oct 23 '15 at 22:05
  • 1
    I suppose strictly speaking the fact that Windows doesn't kill a service's orphaned child processes isn't documented behaviour, so it might change in some future version or as the result of a security update. I would consider it extremely unlikely. In practical terms, so long as the installer doesn't use any Windows features that aren't available in a service context, you should be fine. – Harry Johnston Oct 24 '15 at 00:05
  • @HarryJohnston, could you convert your comment to an answer? – davidpricedev Oct 26 '15 at 14:54

1 Answers1

0

One certain downside is that you lose communication with your service until it finishes restarting. If you're using an installer that updates the files in the folder but doesn't itself report back to you or take remote commands, then any failed update (such as power being lost during the update) could leave the service in a broken state. You'll have to intervene manually. Having a second service to do the updates is a popular approach because the update service can try to recover from a failed update.

Corrodias
  • 734
  • 6
  • 10