Advertisement
Guest User

Untitled

a guest
Jan 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <add key="ServiceName" value="I"/>
  2.  
  3. [RunInstaller(true)]
  4. public class ServiceInstaller1 : Installer
  5. {
  6. internal static string ServiceNameDefault = "My Service";
  7.  
  8. internal static string ServiceName = GetConfigurationValue("ServiceName");
  9.  
  10. /// <summary>
  11. /// Public Constructor for WindowsServiceInstaller.
  12. /// - Put all of your Initialization code here.
  13. /// </summary>
  14. public ServiceInstaller1()
  15. {
  16. var serviceProcessInstaller = new ServiceProcessInstaller();
  17. var serviceInstaller = new ServiceInstaller();
  18.  
  19. //# Service Account Information
  20. serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
  21. //serviceProcessInstaller.Username = null;
  22. //serviceProcessInstaller.Password = null;
  23.  
  24. //# Service Information
  25. serviceInstaller.DisplayName = ServiceName;
  26. serviceInstaller.StartType = ServiceStartMode.Manual;
  27.  
  28. //# This must be identical to the WindowsService.ServiceBase name
  29. //# set in the constructor of WindowsService.cs
  30. serviceInstaller.ServiceName = ServiceName;
  31.  
  32. Installers.Add(serviceProcessInstaller);
  33. Installers.Add(serviceInstaller);
  34. }
  35.  
  36. private static string GetConfigurationValue(string key)
  37. {
  38. Assembly service = Assembly.GetAssembly(typeof(Service));
  39.  
  40. Configuration config = ConfigurationManager.OpenExeConfiguration(service.Location);
  41.  
  42. if (config.AppSettings.Settings[key] != null)
  43. return ServiceNameDefault + " " + config.AppSettings.Settings[key].Value;
  44. else
  45. return ServiceNameDefault;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement