Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <add key="ServiceName" value="I"/>
- [RunInstaller(true)]
- public class ServiceInstaller1 : Installer
- {
- internal static string ServiceNameDefault = "My Service";
- internal static string ServiceName = GetConfigurationValue("ServiceName");
- /// <summary>
- /// Public Constructor for WindowsServiceInstaller.
- /// - Put all of your Initialization code here.
- /// </summary>
- public ServiceInstaller1()
- {
- var serviceProcessInstaller = new ServiceProcessInstaller();
- var serviceInstaller = new ServiceInstaller();
- //# Service Account Information
- serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
- //serviceProcessInstaller.Username = null;
- //serviceProcessInstaller.Password = null;
- //# Service Information
- serviceInstaller.DisplayName = ServiceName;
- serviceInstaller.StartType = ServiceStartMode.Manual;
- //# This must be identical to the WindowsService.ServiceBase name
- //# set in the constructor of WindowsService.cs
- serviceInstaller.ServiceName = ServiceName;
- Installers.Add(serviceProcessInstaller);
- Installers.Add(serviceInstaller);
- }
- private static string GetConfigurationValue(string key)
- {
- Assembly service = Assembly.GetAssembly(typeof(Service));
- Configuration config = ConfigurationManager.OpenExeConfiguration(service.Location);
- if (config.AppSettings.Settings[key] != null)
- return ServiceNameDefault + " " + config.AppSettings.Settings[key].Value;
- else
- return ServiceNameDefault;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement