Exemple #1
0
        public override void Install(IDictionary stateSaver)
        {
            var installers = CreateServiceInstallersFromDescriptor();

            Installers.AddRange(installers.ToArray());

            try
            {
                base.Install(stateSaver);
            }
            catch (Win32Exception ex)
            {
                if (ex.NativeErrorCode == 1073) // "The specified service already exists"
                {
                    Console.Out.WriteLine(ex.Message);
                }
                else
                {
                    throw;
                }
            }

            using (var system = Registry.LocalMachine.OpenSubKey("System"))
            {
                if (system == null)
                {
                    return;
                }

                using (var currentControlSet = system.OpenSubKey("CurrentControlSet"))
                {
                    if (currentControlSet == null)
                    {
                        return;
                    }

                    using (var services = currentControlSet.OpenSubKey("Services"))
                    {
                        if (services == null)
                        {
                            return;
                        }

                        using (var service = services.OpenSubKey(_name, true))
                        {
                            if (service == null)
                            {
                                return;
                            }

                            service.SetValue("Description", _description);

                            var imagePath = (string)service.GetValue("ImagePath");

                            service.SetValue("ImagePath", imagePath);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public ProjectInstaller()
        {
            var serviceProcessInstaller = new ServiceProcessInstaller
            {
                Account = ServiceAccount.LocalSystem
            };

            var serviceInstaller = new ServiceInstaller
            {
                ServiceName = "DNSAgent",
                StartType   = ServiceStartMode.Automatic
            };

            // Automatically start after install
            AfterInstall += (sender, args) =>
            {
                using (var serviceController = new ServiceController(serviceInstaller.ServiceName))
                    serviceController.Start();
            };

            Installers.AddRange(new Installer[]
            {
                serviceProcessInstaller,
                serviceInstaller
            });
        }
Exemple #3
0
        public ProjectInstaller()
        {
            serviceProcessInstaller         = new ServiceProcessInstaller();
            serviceProcessInstaller.Account = ServiceAccount.LocalSystem;

            serviceInstaller = new ServiceInstaller();

            serviceProcessInstaller.Password = null;
            serviceProcessInstaller.Username = null;

            serviceInstaller.ServiceName = DiskAPMService.DiskAPMServiceName;
            serviceInstaller.DisplayName = DiskAPMService.DiskAPMServiceName;
            serviceInstaller.Description = DiskAPMService.DiskAPMServiceDescription;

            serviceInstaller.StartType        = ServiceStartMode.Automatic;
            serviceInstaller.DelayedAutoStart = true;

            serviceInstaller.AfterInstall += (senger, args) =>
            {
                new ServiceController(serviceInstaller.ServiceName).Start();
            };

            Installers.AddRange(new Installer[] { this.serviceProcessInstaller, this.serviceInstaller });

            InitializeComponent();
        }
Exemple #4
0
        private void InitializeComponent()
        {
            var doc = new XmlDocument();

            doc.Load(Config.CfgFile);

            serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller()
            {
                Account                       = System.ServiceProcess.ServiceAccount.LocalSystem
                                     Password = null,
                Username                      = null
            };

            serviceInstaller = new System.ServiceProcess.ServiceInstaller()
            {
                DisplayName        = doc.DocumentElement.SelectSingleNode("/Configuration/Service/LongName").InnerText,
                ServiceName        = doc.DocumentElement.SelectSingleNode("/Configuration/Service/ShortName").InnerText,
                ServicesDependedOn = doc.DocumentElement.SelectSingleNode("/Configuration/Service/Dependencies").InnerText.Split(','),
                StartType          = System.ServiceProcess.ServiceStartMode.Automatic
            }

            Installers.AddRange(new System.Configuration.Install.Installer[] {
                serviceProcessInstaller,
                serviceInstaller
            });
        }
    }
Exemple #5
0
        public SvcInstaller()
        {
            var processInstaller = new ServiceProcessInstaller {
                Account = ServiceAccount.LocalSystem
            };

            var conf             = new Config();
            var serviceInstaller = new ServiceInstaller
            {
                ServiceName = conf.ServiceName,
                DisplayName = conf.DisplayName,
                StartType   = conf.ServiceStartMode,
                Description = conf.Description
            };

            try
            {
                serviceInstaller.ServicesDependedOn = conf.ServicesDependedOn;
            }
            catch (Exception ex) { ClassLogger.Error(ex); }

            try
            {
                serviceInstaller.DelayedAutoStart = conf.DelayedAutoStart;
            }
            catch (Exception ex) { ClassLogger.Error(ex); }

            Installers.AddRange(new Installer[] { serviceInstaller, processInstaller });
        }
Exemple #6
0
        /// <summary>
        /// Инициализирует коллекцию объектов Installer.
        /// </summary>
        /// <remarks>
        /// Имя и отображаемое имя службы устанавливаются в файле конфигурации.
        /// </remarks>
        protected ServiceInstaller()
        {
            var assemblyName = GetType().Assembly.GetName().Name;

            ServiceName        = AppConfig.Setting("service_name", assemblyName);
            ServiceDisplayName = AppConfig.Setting("service_display_name", ServiceName);
            ServiceDescription = AppConfig.Setting("service_description", ServiceDisplayName);

            //
            //    ReSharper disable DoNotCallOverridableMethodsInConstructor
            //
            var serviceInstaller = new System.ServiceProcess.ServiceInstaller
            {
                Description = ServiceDescription,
                ServiceName = ServiceName,
                DisplayName = ServiceDisplayName,
            };
            //
            //    ReSharper restore DoNotCallOverridableMethodsInConstructor
            //

            var serviceProcessInstaller = new ServiceProcessInstaller
            {
                Account  = ServiceAccount.LocalSystem,
                Password = null,
                Username = null
            };

            Installers.AddRange(new Installer[] { serviceInstaller, serviceProcessInstaller });
        }
Exemple #7
0
 /// <summary>
 /// 设计器支持所需的方法 - 不要
 /// 使用代码编辑器修改此方法的内容。
 /// </summary>
 private void InitializeComponent()
 {
     serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
     serviceInstaller        = new System.ServiceProcess.ServiceInstaller();
     //
     // serviceProcessInstaller
     //
     serviceProcessInstaller.Account  = System.ServiceProcess.ServiceAccount.LocalSystem;
     serviceProcessInstaller.Password = null;
     serviceProcessInstaller.Username = null;
     //
     // serviceInstaller
     //
     serviceInstaller.Description = "Insight 基础服务";
     serviceInstaller.DisplayName = "Insight 基础服务";
     serviceInstaller.ServiceName = "Insight Base Service";
     serviceInstaller.StartType   = System.ServiceProcess.ServiceStartMode.Automatic;
     //
     // ProjectInstaller
     //
     Installers.AddRange(new System.Configuration.Install.Installer[] {
         serviceProcessInstaller,
         serviceInstaller
     });
 }
        public ProjectInstaller(string svcname, string username, string password)
        {
            System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
            System.ServiceProcess.ServiceInstaller        serviceInstaller        = new System.ServiceProcess.ServiceInstaller();

            //  check for special users as localsystem, networkservice and localservice
            if (username == null || username.ToLower() == "localsystem")
            {
                serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
            }
            else if (username.ToLower() == "networkservice")
            {
                serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.NetworkService;
            }
            else if (username.ToLower() == "localservice")
            {
                serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalService;
            }
            else
            {
                serviceProcessInstaller.Account  = System.ServiceProcess.ServiceAccount.User;
                serviceProcessInstaller.Username = username;
                serviceProcessInstaller.Password = password;
            }

            serviceInstaller.ServiceName = svcname;
            serviceInstaller.StartType   = System.ServiceProcess.ServiceStartMode.Automatic;
            serviceInstaller.Description = "Service broker external activator";
            serviceInstaller.DisplayName = "External Activator - " + svcname;

            Installers.AddRange(new System.Configuration.Install.Installer[] { serviceProcessInstaller, serviceInstaller });
        }
Exemple #9
0
        public ProjectInstaller()
        {
            // serviceProcessInstaller
            //
            serviceProcessInstaller          = new ServiceProcessInstaller();
            serviceProcessInstaller.Account  = ServiceAccount.NetworkService;
            serviceProcessInstaller.Password = null;
            serviceProcessInstaller.Username = null;

            // serviceInstaller
            //
            serviceInstaller                    = new ServiceInstaller();
            serviceInstaller.ServiceName        = Service.NAME;
            serviceInstaller.DisplayName        = Service.DISPLAY;
            serviceInstaller.Description        = Service.DESCR;
            serviceInstaller.StartType          = ServiceStartMode.Automatic;
            serviceInstaller.ServicesDependedOn = new string[] { "eventlog", "MSMQ" };

            // ProjectInstaller
            //
            Installers.AddRange(new Installer[] {
                serviceProcessInstaller,
                serviceInstaller
            });
        }
Exemple #10
0
        public override void Install(IDictionary stateSaver)
        {
            if (_installers != null)
            {
                Installers.AddRange(_installers);
            }

            var serviceName = BuildServiceName(_settings);

            _logWriter.InfoFormat(Properties.Resources.InstallingServiceIsStarted, serviceName);

            try
            {
                base.Install(stateSaver);

                _installTransaction.Execute(_settings);

                _logWriter.InfoFormat(Properties.Resources.InstallingServiceIsSuccessfullyCompleted, serviceName);
            }
            catch (Exception error)
            {
                error = new InstallException(string.Format(Properties.Resources.InstallingServiceFailed, serviceName), error);
                _logWriter.ErrorFormat(Properties.Resources.InstallingServiceIsCompletedWithErrors, serviceName, error);
                throw error;
            }
        }
Exemple #11
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     _serviceProcessInstaller = new ServiceProcessInstaller();
     _serviceInstaller        = new ServiceInstaller();
     //
     // _serviceProcessInstaller
     //
     _serviceProcessInstaller.Account  = ServiceAccount.LocalSystem;
     _serviceProcessInstaller.Password = null;
     _serviceProcessInstaller.Username = null;
     //
     // _serviceInstaller
     //
     _serviceInstaller.DelayedAutoStart = true;
     _serviceInstaller.Description      = "Эта служба собирает почту с различный ящиков";
     _serviceInstaller.DisplayName      = "Служба сбора почты";
     _serviceInstaller.ServiceName      = "TopCrawler";
     _serviceInstaller.StartType        = ServiceStartMode.Automatic;
     //
     // ProjectInstaller
     //
     Installers.AddRange(new Installer[] {
         _serviceProcessInstaller,
         _serviceInstaller
     });
 }
Exemple #12
0
        public ProjectInstaller()
        {
            try
            {
                using (var container = new UnityContainer())
                {
                    container.AddNewExtension <ServiceConfiguration>();
                    var processInstaller = new ServiceProcessInstaller {
                        Account = ServiceAccount.LocalSystem
                    };
                    var descriptors       = container.Resolve <ServiceDescriptor[]>();
                    var serviceInstallers = from descriptor in descriptors
                                            select new ServiceInstaller
                    {
                        StartType   = ServiceStartMode.Manual,
                        DisplayName = descriptor.Name,
                        ServiceName = descriptor.Key,
                        Description = descriptor.Description
                    };

                    Installers.Add(processInstaller);
                    Installers.AddRange(serviceInstallers.ToArray <Installer>());

                    Logger.Log.Info($"ServiceInstallers: {string.Join(", ", descriptors.Select(d => d.Key))}");
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Fatal(ex);
                throw;
            }
        }
Exemple #13
0
        public TcpServiceInstaller()
        {
            InitializeComponent();

            serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
            serviceInstaller        = new ServiceInstaller();

            serviceProcessInstaller.Account  = System.ServiceProcess.ServiceAccount.LocalSystem;
            serviceProcessInstaller.Password = null;
            serviceProcessInstaller.Username = null;

            serviceInstaller.StartType     = ServiceStartMode.Automatic;
            serviceInstaller.DisplayName   = " TcpServer";
            serviceInstaller.ServiceName   = "TcpServer";
            serviceInstaller.Description   = "Tcp Server Service";
            serviceInstaller.AfterInstall += new System.Configuration.Install.InstallEventHandler(serviceInstaller_AfterInstall);

            var servicesDependedOn = new List <string> {
                "tcpip"
            };

            serviceInstaller.ServicesDependedOn = servicesDependedOn.ToArray();

            Installers.AddRange(new System.Configuration.Install.Installer[] {
                serviceProcessInstaller,
                serviceInstaller
            });
        }
Exemple #14
0
        /// <summary>
        /// Инициализировать установщик службы
        /// </summary>
        protected void Init(string defSvcName, string defDescr)
        {
            // загрузка и проверка свойств службы
            SvcProps svcProps = new SvcProps();

            if (!svcProps.LoadFromFile())
            {
                svcProps.ServiceName = defSvcName;
                svcProps.Description = defDescr;
            }

            if (string.IsNullOrEmpty(svcProps.ServiceName))
            {
                throw new ScadaException(SvcProps.ServiceNameEmptyError);
            }

            // настройка установщика
            ServiceInstaller        serviceInstaller        = new ServiceInstaller();
            ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();

            serviceInstaller.ServiceName = svcProps.ServiceName;
            serviceInstaller.DisplayName = svcProps.ServiceName;
            serviceInstaller.Description = svcProps.Description ?? "";
            serviceInstaller.StartType   = ServiceStartMode.Automatic;

            serviceProcessInstaller.Account  = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Password = null;
            serviceProcessInstaller.Username = null;

            Installers.AddRange(new Installer[] { serviceInstaller, serviceProcessInstaller });
        }
Exemple #15
0
        /// <summary>
        /// Initialize the service installer
        /// </summary>
        protected void Init(string defSvcName, string defDescr)
        {
            // loading and checking service properties
            var svcProps = new SvcProps();

            if (!svcProps.LoadFromFile())
            {
                svcProps.ServiceName = defSvcName;
                svcProps.Description = defDescr;
            }

            if (string.IsNullOrEmpty(svcProps.ServiceName))
            {
                throw new ScadaException(SvcProps.ServiceNameEmptyError);
            }

            // installer setup
            var serviceInstaller        = new ServiceInstaller();
            var serviceProcessInstaller = new ServiceProcessInstaller();

            serviceInstaller.ServiceName = svcProps.ServiceName;
            serviceInstaller.DisplayName = svcProps.ServiceName;
            serviceInstaller.Description = svcProps.Description ?? "";
            serviceInstaller.StartType   = ServiceStartMode.Automatic;

            serviceProcessInstaller.Account  = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Password = null;
            serviceProcessInstaller.Username = null;

            Installers.AddRange(new Installer[] { serviceInstaller, serviceProcessInstaller });
        }
Exemple #16
0
 /// <summary>
 ///    Required method for Designer support - do not modify
 ///    the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     _serviceInstaller        = new System.ServiceProcess.ServiceInstaller();
     _serviceProcessInstaller =
         new System.ServiceProcess.ServiceProcessInstaller();
     //
     // serviceInstaller
     //
     _serviceInstaller.Description = "Mocument.ReverseProxyService";
     _serviceInstaller.DisplayName = "Mocument.ReverseProxyService";
     _serviceInstaller.ServiceName = "Mocument.ReverseProxyService";
     //
     // serviceProcessInstaller
     //
     _serviceProcessInstaller.Account =
         System.ServiceProcess.ServiceAccount.LocalService;
     _serviceProcessInstaller.Password = null;
     _serviceProcessInstaller.Username = null;
     //
     // ServiceInstaller
     //
     Installers.AddRange(new System.Configuration.Install.Installer[] {
         _serviceProcessInstaller,
         _serviceInstaller
     });
 }
Exemple #17
0
        public ProjectInstaller()
        {
            var serviceProcessInstaller = new ServiceProcessInstaller
            {
                Account = ServiceAccount.LocalSystem
            };

            var serviceInstaller = new ServiceInstaller
            {
                ServiceName = $"{Program.HostName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
                StartType   = ServiceStartMode.Automatic
            };

            // Automatically start after install
            AfterInstall += (sender, args) =>
            {
                using (var serviceController = new ServiceController(serviceInstaller.ServiceName))
                    serviceController.Start();
            };

            Installers.AddRange(new Installer[]
            {
                serviceProcessInstaller,
                serviceInstaller
            });
        }
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     _serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
     _serviceInstaller        = new System.ServiceProcess.ServiceInstaller();
     //
     // ServiceProcessInstaller configuration
     //
     _serviceProcessInstaller.Account  = System.ServiceProcess.ServiceAccount.LocalService;
     _serviceProcessInstaller.Password = null;
     _serviceProcessInstaller.Username = null;
     //
     // ServiceInstaller configuration
     //
     _serviceInstaller.Description   = "Test.WindowsServiceWithHealthcheck";
     _serviceInstaller.DisplayName   = "Test.WindowsServiceWithHealthcheck";
     _serviceInstaller.ServiceName   = "Test.WindowsServiceWithHealthcheck";
     _serviceInstaller.AfterInstall += new System.Configuration.Install.InstallEventHandler(WindowsServiceWithHealthcheck_AfterInstall);
     //
     // ServiceInstaller registration
     //
     Installers.AddRange(new System.Configuration.Install.Installer[] {
         _serviceProcessInstaller,
         _serviceInstaller
     });
 }
 void InitializeComponent()
 {
     _serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
     _serviceInstaller1        = new System.ServiceProcess.ServiceInstaller();
     //
     // _serviceProcessInstaller1
     //
     _serviceProcessInstaller1.Account  = System.ServiceProcess.ServiceAccount.LocalSystem;
     _serviceProcessInstaller1.Password = null;
     _serviceProcessInstaller1.Username = null;
     //
     // _serviceInstaller1
     //
     _serviceInstaller1.Description = _serviceDescription;
     _serviceInstaller1.DisplayName = _serviceName;
     _serviceInstaller1.ServiceName = _serviceName;
     //
     // ProjectInstaller
     //
     Installers.AddRange(new Installer[]
     {
         _serviceProcessInstaller1,
         _serviceInstaller1
     });
 }
Exemple #20
0
        /// <summary>
        /// The constructor.
        /// </summary>
        public CustomInstaller()
        {
            // Config service installer
            var serviceName = "Dache Cache Host";

            _serviceVersion = Assembly.GetExecutingAssembly().GetName().Version;

            // Set some service information
            _serviceInstaller.DisplayName = serviceName; //+ " " + _serviceVersion;
            _serviceInstaller.ServiceName = serviceName; //+ " " + _serviceVersion;
            _serviceInstaller.StartType   = System.ServiceProcess.ServiceStartMode.Automatic;

            // Perform install customizations
            BeforeInstall += CustomInstaller_BeforeInstall;
            // Perform rollback uninstall
            AfterRollback += CustomInstaller_BeforeUninstall;

            // Perform uninstall customizations
            BeforeUninstall += CustomInstaller_BeforeUninstall;

            // Now append version and assign description
            _serviceInstaller.Description = "Hosts an instance of the distributed cache.";

            // Config service process installer to install as Network Service
            _serviceProcessInstaller.Account = ServiceAccount.NetworkService;

            // Now add the Installers
            Installers.AddRange(new Installer[] { _serviceInstaller, _serviceProcessInstaller });
        }
Exemple #21
0
 public void InitializeInstallers()
 {
     Installers.AddRange(new Installer[]
     {
         Configuration.GetServiceInstaller(),
         Configuration.GetProcessInstaller()
     });
 }
Exemple #22
0
        public ServiceInstaller()
        {
            InitializeComponent();

            serviceInstallers = Program.CreateServiceInstallers();

            Installers.AddRange(serviceInstallers.Get() as Installer[]);

            this.BeforeInstall += ServiceInstaller_BeforeInstall;
        }
Exemple #23
0
        public override void Uninstall(IDictionary savedState)
        {
            Installers.AddRange(_installers);
            if (_log.IsInfoEnabled)
            {
                _log.InfoFormat("Uninstalling {0} service", _settings.Name);
            }

            base.Uninstall(savedState);
        }
Exemple #24
0
 protected ManagedServiceInstallerBase()
 {
     _ServiceProcessInstaller = new ServiceProcessInstaller();
     _ServiceInstaller        = new ServiceInstaller();
     InitializeInstaller();
     Installers.AddRange(new Installer[] {
         _ServiceProcessInstaller,
         _ServiceInstaller
     });
 }
        public ProjectInstallerForHelper(bool delayedAutoStart = true)
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new System.ServiceProcess.ServiceInstaller();
            serviceInstaller.DelayedAutoStart = delayedAutoStart;

            Installers.AddRange(new Installer[] {
                processInstaller,
                serviceInstaller
            });
        }
        public InstallationConfiguration AddInstallers(params IInstaller[] installers)
        {
            if (installers == null)
            {
                throw new ArgumentNullException(nameof(installers));
            }

            Installers.AddRange(installers);

            return(this);
        }
Exemple #27
0
        public ProjectInstaller()
        {
            _serviceProcessInstaller         = new ServiceProcessInstaller();
            _serviceProcessInstaller.Account = ServiceAccount.LocalSystem;

            _serviceInstaller           = new ServiceInstaller();
            _serviceInstaller.StartType = ServiceStartMode.Automatic;

            //Add installers to the collection.
            Installers.AddRange(new Installer[] { _serviceInstaller, _serviceProcessInstaller });
        }
Exemple #28
0
        public override void Uninstall(IDictionary savedState)
        {
            var installers = CreateServiceInstallersFromDescriptor();

            Installers.AddRange(installers.ToArray());

            var state = new Hashtable {
                { "ServiceName", _name }, { "Description", _description }, { "DisplayName", _displayName }
            };

            base.Uninstall(state);
        }
        public ThisServiceInstaller()
        {
            serviceProcessInstaller = new ServiceProcessInstaller();
            serviceInstaller        = new ServiceInstaller();

            // Here you can set properties on serviceProcessInstaller or register event handlers
            serviceProcessInstaller.Account = ServiceAccount.User;

            serviceInstaller.ServiceName = ConfigurationManager.AppSettings["MicroErpApi.ServiceName"];
            serviceInstaller.Description = ConfigurationManager.AppSettings["MicroErpApi.ServiceDescription"];
            Installers.AddRange(new Installer[] { serviceProcessInstaller, serviceInstaller });
        }
 public ServiceInstaller()
 {
     Installers.AddRange(new Installer[]
     {
         new ServiceProcessInstaller {
             Account = ServiceAccount.LocalService
         },
         new System.ServiceProcess.ServiceInstaller {
             ServiceName = Program.ServiceName
         }
     });
 }