HardWorkingServiceInstaller.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using HardWorkingService.Install;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Configuration.Install;
  6. using System.Linq;
  7. using System.ServiceProcess;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace HardWorkingService
  11. {
  12. [RunInstaller(true)]
  13. public partial class HardWorkingServiceInstaller : System.Configuration.Install.Installer
  14. {
  15. public HardWorkingServiceInstaller() : base()
  16. {
  17. var serviceProcessInstaller = new ServiceProcessInstaller();
  18. var serviceInstaller = new ServiceInstaller();
  19. //Service Account Information
  20. serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
  21. serviceProcessInstaller.Username = null;
  22. serviceProcessInstaller.Password = null;
  23. //Service Information
  24. serviceInstaller.DisplayName = InstallTimeConfigurationManager.GetConfigurationValue("ServiceDisplayName");
  25. serviceInstaller.Description = InstallTimeConfigurationManager.GetConfigurationValue("ServiceDescription");
  26. serviceInstaller.StartType = ServiceStartMode.Automatic;
  27. serviceInstaller.DelayedAutoStart = true;
  28. //This must be identical to the WindowsService.ServiceBase name
  29. //set in the constructor of WindowsService.cs
  30. serviceInstaller.ServiceName = InstallTimeConfigurationManager.GetConfigurationValue("SystemServiceName");
  31. this.Installers.Add(serviceProcessInstaller);
  32. this.Installers.Add(serviceInstaller);
  33. this.Committed += Installer_Committed;
  34. }
  35. private void Installer_Committed(Object sender, InstallEventArgs e)
  36. {
  37. //auto start the service once the installation is finished
  38. var controller = new ServiceController(InstallTimeConfigurationManager.GetConfigurationValue("SystemServiceName"));
  39. controller.Start();
  40. }
  41. }
  42. }