daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Configuration;
  6. using System.Configuration.Install;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.ServiceProcess;
  10.  
  11.  
  12. namespace xxx
  13. {
  14.     [RunInstaller(true)]
  15.     public partial class ProjectInstaller : System.Configuration.Install.Installer
  16.     {
  17.         public ProjectInstaller()
  18.         {
  19.             InitializeComponent();
  20.  
  21.             this.Installers.Clear();
  22.  
  23.             ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
  24.             serviceProcessInstaller.Password = null;
  25.             serviceProcessInstaller.Username = null;
  26.             serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
  27.  
  28.             // serviceInstaller
  29.             ServiceInstaller serviceInstaller = new ServiceInstaller();
  30.             serviceInstaller.ServiceName = GetServiceNameAppConfig("SERVICE_NAME");
  31.             serviceInstaller.DisplayName = GetServiceNameAppConfig("SERVICE_DISPLAY_NAME");
  32.             serviceInstaller.StartType = ServiceStartMode.Automatic;
  33.             serviceInstaller.Description = GetServiceNameAppConfig("SERVICE_DESCRIPTION");
  34.  
  35.             // kill the default event log installer
  36.             serviceInstaller.Installers.Clear();
  37.  
  38.             // add all installers
  39.             this.Installers.AddRange(new Installer[] {
  40.                serviceProcessInstaller, serviceInstaller
  41.             });
  42.         }
  43.  
  44.         public string GetServiceNameAppConfig(string serviceName)
  45.         {
  46.             var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(ProjectInstaller)).Location);
  47.             return config.AppSettings.Settings[serviceName].Value;
  48.         }
  49.  
  50.         private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
  51.         {
  52.  
  53.         }
  54.  
  55.         private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
  56.         {
  57.  
  58.         }
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top