public CustomInstaller(Service service)
        {
            _service = service;
            Installers.Add(GetServiceInstaller());
            Installers.Add(GetServiceProcessInstaller());
            var baseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
            Context = new InstallContext(
                null,
                new[]
                    {
                        "/LogToConsole=true",
                        "/InstallStateDir=" + Path.Combine(baseDir, "service-install.state"),
                        "/LogFile=" + Path.Combine(baseDir, "service-install.log")
                    });

            foreach (string key in Context.Parameters.Keys)
            {
                Writer.WriteLine("{0}={1}", key, Context.Parameters[key]);
            }

            if (_service.StartMode == ServiceStartMode.Automatic)
            {
                Committed += (sender, args) => new ServiceController(service.ServiceName).Start();
            }
        }
        public void Save(Service options)
        {
            if (Exists(options.ServiceName))
            {
                Delete(options.ServiceName);
            }

            Add(options);
        }
        public void Add(Service options)
        {
            if (Exists(options.ServiceName))
            {
                throw new InvalidOperationException("service already exists with the name '" + options.ServiceName + "'");
            }

            new CustomInstaller(options).Install(new Hashtable());

            //ManagedInstallerClass.InstallHelper(new[] { Assembly.GetEntryAssembly().Location });
            Log.InfoFormat("installed {0}", options.ServiceName);
        }
        public void Run()
        {
            if (List)
            {
                ListCommandsThatCanBeRunAsService();
                return;
            }

            var service = new Service
                {
                    ServiceName = ServiceName,
                    DisplayName = DisplayName,
                    Description = Description,
                    Account = Account,
                    Username = Username,
                    Password = Password,
                    StartMode = StartMode,
                    CommandLine = CommandLine
                };

            if (ShowDefaults)
            {
                Writer.WriteLine(service.Dump());
                return;
            }

            Writer.WriteLine("You are about to install this service:");
            Writer.WriteLine("  service name: " + service.ServiceName);
            Writer.WriteLine("  display name: " + service.DisplayName);
            Writer.WriteLine("  description : " + service.Description);

            if (!AlterDataOptions.Continue("Would you like to continue?"))
            {
                return;
            }

            if (ForceReinstall)
            {
                _servicesRepository.Save(service);
            }
            else
            {
                _servicesRepository.Add(service);
            }
        }