BackgroundServiceInstaller.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.ComponentModel;
  3. using System.ServiceProcess;
  4. namespace MediaBrowser.ServerApplication
  5. {
  6. [RunInstaller(true)]
  7. public class BackgroundServiceInstaller : System.Configuration.Install.Installer
  8. {
  9. public BackgroundServiceInstaller()
  10. {
  11. var process = new ServiceProcessInstaller
  12. {
  13. Account = ServiceAccount.LocalSystem
  14. };
  15. var serviceAdmin = new ServiceInstaller
  16. {
  17. StartType = ServiceStartMode.Manual,
  18. ServiceName = BackgroundService.Name,
  19. DisplayName = BackgroundService.DisplayName,
  20. DelayedAutoStart = true,
  21. Description = "The windows background service for Media Browser Server."
  22. };
  23. // Microsoft didn't add the ability to add a
  24. // description for the services we are going to install
  25. // To work around this we'll have to add the
  26. // information directly to the registry but I'll leave
  27. // this exercise for later.
  28. // now just add the installers that we created to our
  29. // parents container, the documentation
  30. // states that there is not any order that you need to
  31. // worry about here but I'll still
  32. // go ahead and add them in the order that makes sense.
  33. Installers.Add(process);
  34. Installers.Add(serviceAdmin);
  35. }
  36. protected override void OnBeforeInstall(IDictionary savedState)
  37. {
  38. Context.Parameters["assemblypath"] = "\"" +
  39. Context.Parameters["assemblypath"] + "\" " + GetStartArgs();
  40. base.OnBeforeInstall(savedState);
  41. }
  42. protected override void OnBeforeUninstall(IDictionary savedState)
  43. {
  44. Context.Parameters["assemblypath"] = "\"" +
  45. Context.Parameters["assemblypath"] + "\" " + GetStartArgs();
  46. base.OnBeforeUninstall(savedState);
  47. }
  48. private string GetStartArgs()
  49. {
  50. return "-service";
  51. }
  52. }
  53. }