BackgroundServiceInstaller.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Will ensure the network is available
  23. ServicesDependedOn = new[] { "LanmanServer" }
  24. };
  25. // Microsoft didn't add the ability to add a
  26. // description for the services we are going to install
  27. // To work around this we'll have to add the
  28. // information directly to the registry but I'll leave
  29. // this exercise for later.
  30. // now just add the installers that we created to our
  31. // parents container, the documentation
  32. // states that there is not any order that you need to
  33. // worry about here but I'll still
  34. // go ahead and add them in the order that makes sense.
  35. Installers.Add(process);
  36. Installers.Add(serviceAdmin);
  37. }
  38. protected override void OnBeforeInstall(IDictionary savedState)
  39. {
  40. Context.Parameters["assemblypath"] = "\"" +
  41. Context.Parameters["assemblypath"] + "\" " + GetStartArgs();
  42. base.OnBeforeInstall(savedState);
  43. }
  44. protected override void OnBeforeUninstall(IDictionary savedState)
  45. {
  46. Context.Parameters["assemblypath"] = "\"" +
  47. Context.Parameters["assemblypath"] + "\" " + GetStartArgs();
  48. base.OnBeforeUninstall(savedState);
  49. }
  50. private string GetStartArgs()
  51. {
  52. return "-service";
  53. }
  54. }
  55. }