1

I am making a windows service that can be automatically updated. The plan is to have a console application that runs when there is a new version of the service available. This application would uninstalls and re-installs the service with the new version by referencing the MSI. So, I would like a copy of the MSI in the Application Folder.

Can an MSI place a copy of itself in the Application Folder on installation? If so, how?

Thanks in advance!

HamChunck
  • 23
  • 3
  • There are probably better and more orthodox ways than the one your proposing. See http://stackoverflow.com/questions/246886/process-for-updating-a-windows-service-automated-or-is-it-manual, http://stackoverflow.com/questions/106765/i-want-my-c-sharp-windows-service-to-automatically-update-itself#106799, and http://stackoverflow.com/questions/691663/auto-update-library-for-net – Robert Harvey Mar 20 '13 at 16:08
  • @RobertHarvey, I've read these posts before and they suggest to use a separate process to stop and restart the service. Also they recommend using a installer. This is how i'm trying to implement the update routine. Could you provide more clarification as to how my solution could be improved? thanks. – HamChunck Mar 20 '13 at 16:37
  • There's a good example here: http://stackoverflow.com/a/328211 – Robert Harvey Mar 20 '13 at 16:38

2 Answers2

0

The approach is initially wrong.

There's a lot of opportunities to upgrade something, if a new version is available.

  1. Check them on install (some installer has autodownloader functions) - partial solution, no auto upgrade opportunity
  2. The service needs to discover new versions (background thread) - need some development [msi silent install in the background] <- prefered
  3. Centralized deploy - there are solutions for centralized install, even MS, IBM etc. has tools for this. So if a new solution is ready, then no matter what you can deploy them in your domain. <- not so cost effective, used tippicaly by large companies

+1 Also there are some ways you can do this without stopping a service. In C# you can load, and unload versioned assemblies on the fly, but makes your developer life real hard.

If you chose the 2.nd option, then you can start a "process asyncronly" from code so the installer will run with default options (search silent install) although you can define custom settings "my.msi -s config.file". The installer needs to be prepared for checking and stopping the service itself if already exists.

This is a complex story, search for some keywords I've mentioned.

nBalu
  • 76
  • 4
  • Thanks for the response! The second option is what i'm looking at. I want my asynchronous process to call my MSI silently. This i want my MSI to create a copy of itself in the Application Folder. Does that make sense? – HamChunck Mar 20 '13 at 17:13
  • As Rob mentioned in the prev. answer, there's no need to save, the original installer ITSELF unless you want to reverse ability. Becouse this can couse infinite loops if you are not careful. You have to download it in the background, then perform the silent install in the background. – nBalu Mar 21 '13 at 10:06
0

Instead of trying to get the .msi to copy itself (which requires some real hacks to make the self-reference work), I'd recommend just having the new .msi upgrade the old .msi file. Then you just need the new .msi and the old .msi isn't necessary.

Alternatively, you could put things in a Bundle (using the Burn engine from the WiX toolset) and it has a way to do automatic updates via the Bundle.

Rob Mensching
  • 33,834
  • 5
  • 90
  • 130