Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Configuration.Install;
- using System.Linq;
- using System.Reflection;
- using System.ServiceProcess;
- namespace xxx
- {
- [RunInstaller(true)]
- public partial class ProjectInstaller : System.Configuration.Install.Installer
- {
- public ProjectInstaller()
- {
- InitializeComponent();
- this.Installers.Clear();
- ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
- serviceProcessInstaller.Password = null;
- serviceProcessInstaller.Username = null;
- serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
- // serviceInstaller
- ServiceInstaller serviceInstaller = new ServiceInstaller();
- serviceInstaller.ServiceName = GetServiceNameAppConfig("SERVICE_NAME");
- serviceInstaller.DisplayName = GetServiceNameAppConfig("SERVICE_DISPLAY_NAME");
- serviceInstaller.StartType = ServiceStartMode.Automatic;
- serviceInstaller.Description = GetServiceNameAppConfig("SERVICE_DESCRIPTION");
- // kill the default event log installer
- serviceInstaller.Installers.Clear();
- // add all installers
- this.Installers.AddRange(new Installer[] {
- serviceProcessInstaller, serviceInstaller
- });
- }
- public string GetServiceNameAppConfig(string serviceName)
- {
- var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(ProjectInstaller)).Location);
- return config.AppSettings.Settings[serviceName].Value;
- }
- private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
- {
- }
- private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement