public void InstallService(InstallHostSettings settings, IDictionary<string, object> arguments = null, Action<InstallEventArgs> beforeInstall = null, Action<InstallEventArgs> afterInstall = null, Action<InstallEventArgs> beforeRollback = null, Action<InstallEventArgs> afterRollback = null)
		{
			var commandLine = BuildCommandLine(settings, arguments);

			using (var installer = CreateInstaller(settings, commandLine))
			{
				if (beforeInstall != null)
				{
					installer.BeforeInstall += (sender, args) => beforeInstall(args);
				}

				if (afterInstall != null)
				{
					installer.AfterInstall += (sender, args) => afterInstall(args);
				}

				if (beforeRollback != null)
				{
					installer.BeforeRollback += (sender, args) => beforeRollback(args);
				}

				if (afterRollback != null)
				{
					installer.AfterRollback += (sender, args) => afterRollback(args);
				}

				Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

				installer.Install(new Hashtable());
			}
		}
예제 #2
0
 void ExecutePreActions(InstallHostSettings settings)
 {
     foreach (Action <InstallHostSettings> action in _preActions)
     {
         action(_installSettings);
     }
 }
        public void InstallService(InstallHostSettings settings, IDictionary <string, object> arguments = null, Action <InstallEventArgs> beforeInstall = null, Action <InstallEventArgs> afterInstall = null, Action <InstallEventArgs> beforeRollback = null, Action <InstallEventArgs> afterRollback = null)
        {
            var commandLine = BuildCommandLine(settings, arguments);

            using (var installer = CreateInstaller(settings, commandLine))
            {
                if (beforeInstall != null)
                {
                    installer.BeforeInstall += (sender, args) => beforeInstall(args);
                }

                if (afterInstall != null)
                {
                    installer.AfterInstall += (sender, args) => afterInstall(args);
                }

                if (beforeRollback != null)
                {
                    installer.BeforeRollback += (sender, args) => beforeRollback(args);
                }

                if (afterRollback != null)
                {
                    installer.AfterRollback += (sender, args) => afterRollback(args);
                }

                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                installer.Install(new Hashtable());
            }
        }
예제 #4
0
        public void InstallService(
            InstallHostSettings settings,
            Action <InstallHostSettings> beforeInstall,
            Action afterInstall,
            Action beforeRollback,
            Action afterRollback)
        {
            using (var installer = new SpHostServiceInstaller(settings, _hostConfigurator))
            {
                Action <InstallEventArgs> before = x =>
                {
                    beforeInstall?.Invoke(settings);
                };

                Action <InstallEventArgs> after = x =>
                {
                    afterInstall?.Invoke();
                };

                Action <InstallEventArgs> before2 = x =>
                {
                    beforeRollback?.Invoke();
                };

                Action <InstallEventArgs> after2 = x =>
                {
                    afterRollback?.Invoke();
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
        public void InstallService(
            InstallHostSettings settings, 
            Action<InstallHostSettings> beforeInstall, 
            Action afterInstall, 
            Action beforeRollback,
            Action afterRollback)
        {
            using (var installer = new SpHostServiceInstaller(settings, _hostConfigurator))
            {
                Action<InstallEventArgs> before = x =>
                {
                    beforeInstall?.Invoke(settings);
                };

                Action<InstallEventArgs> after = x =>
                {
                    afterInstall?.Invoke();
                };

                Action<InstallEventArgs> before2 = x =>
                {
                    beforeRollback?.Invoke();
                };

                Action<InstallEventArgs> after2 = x =>
                {
                    afterRollback?.Invoke();
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
        public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeInstall != null)
                    {
                        beforeInstall(settings);
                        installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                        installer.ServiceProcessInstaller.Account  = settings.Credentials.Account;

                        // Group Managed Service Account (gMSA) workaround per
                        // https://connect.microsoft.com/VisualStudio/feedback/details/795196/service-process-installer-should-support-virtual-service-accounts
                        if (settings.Credentials.Account == ServiceAccount.User &&
                            settings.Credentials.Username != null &&
                            settings.Credentials.Username.EndsWith("$", StringComparison.InvariantCulture))
                        {
                            _log.InfoFormat("Installing as gMSA {0}.", settings.Credentials.Username);
                            installer.ServiceProcessInstaller.Password = null;
                            installer.ServiceProcessInstaller
                            .GetType()
                            .GetField("haveLoginInfo", BindingFlags.Instance | BindingFlags.NonPublic)
                            .SetValue(installer.ServiceProcessInstaller, true);
                        }
                        else
                        {
                            installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                        }
                    }
                };

                Action <InstallEventArgs> after = x =>
                {
                    if (afterInstall != null)
                    {
                        afterInstall();
                    }
                };

                Action <InstallEventArgs> before2 = x =>
                {
                    if (beforeRollback != null)
                    {
                        beforeRollback();
                    }
                };

                Action <InstallEventArgs> after2 = x =>
                {
                    if (afterRollback != null)
                    {
                        afterRollback();
                    }
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
예제 #7
0
        public SpHostServiceInstaller(InstallHostSettings settings, HostConfigurator configurator)
        {
            _hostConfigurator = configurator;

            _installer = CreateInstaller(settings);

            _transactedInstaller = CreateTransactedInstaller(_installer);
        }
        public SpHostServiceInstaller(InstallHostSettings settings, HostConfigurator configurator)
        {
            _hostConfigurator = configurator;

            _installer = CreateInstaller(settings);

            _transactedInstaller = CreateTransactedInstaller(_installer);
        }
예제 #9
0
        private static void EnsureConfiguration(InstallHostSettings installHostSettings)
        {
            var fsm = new FileSystemManger();

            fsm.EnsureFolder(_config.SourceFolder);
            fsm.EnsureFolder(_config.ImporterLogFolder);
            fsm.EnsureFolder(_config.ResultFolder);
            fsm.EnsureFolder(_config.TempFolder);
        }
예제 #10
0
        static Installer CreateInstaller(InstallHostSettings settings)
        {
            var installers = new Installer[]
            {
                ConfigureServiceInstaller(settings, settings.Dependencies, settings.StartMode),
                ConfigureServiceProcessInstaller(settings.Account, settings.Username, settings.Password)
            };

            return(CreateHostInstaller(settings, installers));
        }
예제 #11
0
        static Installer CreateInstaller(InstallHostSettings settings)
        {
            var installers = new Installer[]
                {
                    ConfigureServiceInstaller(settings, settings.Dependencies, settings.StartMode),
                    ConfigureServiceProcessInstaller(settings.Account, settings.Username, settings.Password)
                };

            return CreateHostInstaller(settings, installers);
        }
        public void InstallService(InstallHostSettings settings, Action<InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            var installer = new LinuxHostServiceInstallerImpl();

            Action<InstallEventArgs> tryBeforeInstall = x => beforeInstall?.Invoke(settings);
            Action<InstallEventArgs> tryAfterInstall = x => afterInstall?.Invoke();
            Action<InstallEventArgs> tryBeforeRollback = x => beforeRollback?.Invoke();
            Action<InstallEventArgs> tryAfterRollback = x => afterRollback?.Invoke();

            installer.InstallService(settings, _arguments, tryBeforeInstall, tryAfterInstall, tryBeforeRollback, tryAfterRollback);
        }
예제 #13
0
        public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            var installer = new LinuxHostServiceInstallerImpl();

            Action <InstallEventArgs> tryBeforeInstall  = x => beforeInstall?.Invoke(settings);
            Action <InstallEventArgs> tryAfterInstall   = x => afterInstall?.Invoke();
            Action <InstallEventArgs> tryBeforeRollback = x => beforeRollback?.Invoke();
            Action <InstallEventArgs> tryAfterRollback  = x => afterRollback?.Invoke();

            installer.InstallService(settings, _arguments, tryBeforeInstall, tryAfterInstall, tryBeforeRollback, tryAfterRollback);
        }
예제 #14
0
        public InstallHost(HostEnvironment environment, HostSettings settings, HostStartMode startMode,
            IEnumerable<string> dependencies,
            Credentials credentials, IEnumerable<Action> preActions, IEnumerable<Action> postActions, bool sudo)
        {
            _environment = environment;
            _settings = settings;

            _installSettings = new InstallServiceSettingsImpl(settings, credentials, startMode, dependencies.ToArray());

            _preActions = preActions;
            _postActions = postActions;
            _sudo = sudo;
        }
예제 #15
0
        public InstallHost(HostEnvironment environment, HostSettings settings, HostStartMode startMode,
                           IEnumerable <string> dependencies,
                           Credentials credentials, IEnumerable <Action> preActions, IEnumerable <Action> postActions, bool sudo)
        {
            _environment = environment;
            _settings    = settings;

            _installSettings = new InstallServiceSettingsImpl(settings, credentials, startMode, dependencies.ToArray());

            _preActions  = preActions;
            _postActions = postActions;
            _sudo        = sudo;
        }
예제 #16
0
        private Installer CreateInstaller(InstallHostSettings settings)
        {
            var installers = new Installer[]
            {
                ConfigureServiceInstaller(settings, settings.Dependencies, settings.StartMode),
                ConfigureServiceProcessInstaller(settings.Credentials.Account, settings.Credentials.Username, settings.Credentials.Password)
            };

            //DO not auto create EventLog Source while install service
            //MSDN: When the installation is performed, it automatically creates an EventLogInstaller to install the event log source associated with the ServiceBase derived class. The Log property for this source is set by the ServiceInstaller constructor to the computer's Application log. When you set the ServiceName of the ServiceInstaller (which should be identical to the ServiceBase..::.ServiceName of the service), the Source is automatically set to the same value. In an installation failure, the source's installation is rolled-back along with previously installed services.
            //MSDN: from EventLog.CreateEventSource Method (String, String) : an ArgumentException thrown when The first 8 characters of logName match the first 8 characters of an existing event log name.
            RemoveEventLogInstallers(installers);

            return(CreateHostInstaller(settings, installers));
        }
        public void InstallService(InstallHostSettings settings, Action beforeInstall, Action afterInstall)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action<InstallEventArgs> before = x =>
                    {
                        if (beforeInstall != null)
                            beforeInstall();
                    };

                Action<InstallEventArgs> after = x =>
                    {
                        if (afterInstall != null)
                            afterInstall();
                    };

                installer.InstallService(before, after);
            }
        }
예제 #18
0
        private static void AddServiceStartupOption(InstallHostSettings settings, IEnumerable <string> paths)
        {
            using (RegistryKey system = Registry.LocalMachine.OpenSubKey("System"))
            {
                if (system == null)
                {
                    Logger.Error(@"Не удалось найти в системном реестре ключ HKEY_LOCAL_MACHINE\SYSTEM");
                    return;
                }

                using (RegistryKey currentControlSet = system.OpenSubKey("CurrentControlSet"))
                {
                    if (currentControlSet == null)
                    {
                        Logger.Error(@"Не удалось найти в системно реестре ключ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet");
                        return;
                    }

                    using (RegistryKey services = currentControlSet.OpenSubKey("Services"))
                    {
                        if (services == null)
                        {
                            Logger.Error(@"Не удалось найти в системно реестре ключ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services");
                            return;
                        }

                        using (RegistryKey service = services.OpenSubKey(settings.ServiceName, true))
                        {
                            if (service == null)
                            {
                                Logger.Error(@"Не удалось найти в системно реестре ключ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\" + settings.ServiceName);
                                return;
                            }

                            var imagePath = (string)service.GetValue("ImagePath");
                            imagePath += " -path:" + string.Join(PathSeparator, paths);
                            service.SetValue("ImagePath", imagePath);
                        }
                    }
                }
            }
        }
예제 #19
0
        public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeInstall != null)
                    {
                        beforeInstall(settings);
                        installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                        installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                        installer.ServiceProcessInstaller.Account  = settings.Credentials.Account;
                    }
                };

                Action <InstallEventArgs> after = x =>
                {
                    if (afterInstall != null)
                    {
                        afterInstall();
                    }
                };

                Action <InstallEventArgs> before2 = x =>
                {
                    if (beforeRollback != null)
                    {
                        beforeRollback();
                    }
                };

                Action <InstallEventArgs> after2 = x =>
                {
                    if (afterRollback != null)
                    {
                        afterRollback();
                    }
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
예제 #20
0
        protected override Installer CreateInstaller(InstallHostSettings settings, string commandLine)
        {
            var baseInstallers = new Installer[]
            {
                CreateServiceInstaller(settings, settings.Dependencies, settings.StartMode),
                CreateServiceProcessInstaller(settings.Credentials?.Account, settings.Credentials?.Username, settings.Credentials?.Password)
            };

            foreach (var installer in baseInstallers)
            {
                var eventLogInstallers = installer.Installers.OfType <EventLogInstaller>().ToArray();

                foreach (var eventLogInstaller in eventLogInstallers)
                {
                    installer.Installers.Remove(eventLogInstaller);
                }
            }

            var mainInstaller = new HostInstaller(settings, commandLine, baseInstallers);

            return(CreateTransactedInstaller(mainInstaller));
        }
예제 #21
0
        static Installer CreateInstaller(InstallHostSettings settings)
        {
            var installers = new Installer[]
                {
                    ConfigureServiceInstaller(settings, settings.Dependencies, settings.StartMode),
                    ConfigureServiceProcessInstaller(settings.Account, settings.Username, settings.Password)
                };

            //DO not auto create EventLog Source while install service
            //MSDN: When the installation is performed, it automatically creates an EventLogInstaller to install the event log source associated with the ServiceBase derived class. The Log property for this source is set by the ServiceInstaller constructor to the computer's Application log. When you set the ServiceName of the ServiceInstaller (which should be identical to the ServiceBase..::.ServiceName of the service), the Source is automatically set to the same value. In an installation failure, the source's installation is rolled-back along with previously installed services.
            //MSDN: from EventLog.CreateEventSource Method (String, String) : an ArgumentException thrown when The first 8 characters of logName match the first 8 characters of an existing event log name.
            foreach (var installer in installers)
            {
                var eventLogInstallers = installer.Installers.OfType<EventLogInstaller>().ToArray();
                foreach (var eventLogInstaller in eventLogInstallers)
                {
                    installer.Installers.Remove(eventLogInstaller);
                }
            }

            return CreateHostInstaller(settings, installers);
        }
        public void InstallService(InstallHostSettings settings, Action beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeInstall != null)
                    {
                        beforeInstall();
                    }
                };

                Action <InstallEventArgs> after = x =>
                {
                    if (afterInstall != null)
                    {
                        afterInstall();
                    }
                };

                Action <InstallEventArgs> before2 = x =>
                {
                    if (beforeRollback != null)
                    {
                        beforeRollback();
                    }
                };

                Action <InstallEventArgs> after2 = x =>
                {
                    if (afterRollback != null)
                    {
                        afterRollback();
                    }
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
		protected override Installer CreateInstaller(InstallHostSettings settings, string commandLine)
		{
			var baseInstallers = new Installer[]
			{
				CreateServiceInstaller(settings, settings.Dependencies, settings.StartMode),
				CreateServiceProcessInstaller(settings.Account, settings.Username, settings.Password)
			};

			foreach (var installer in baseInstallers)
			{
				var eventLogInstallers = installer.Installers.OfType<EventLogInstaller>().ToArray();

				foreach (var eventLogInstaller in eventLogInstallers)
				{
					installer.Installers.Remove(eventLogInstaller);
				}
			}

			var mainInstaller = new HostInstaller(settings, commandLine, baseInstallers);

			return CreateTransactedInstaller(mainInstaller);
		}
		public void InstallService(InstallHostSettings settings, Action beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
		{
			var installer = new LinuxHostServiceInstallerImpl();

			Action<InstallEventArgs> tryBeforeInstall = x =>
				{
					if (beforeInstall != null)
					{
						beforeInstall();
					}
				};

			Action<InstallEventArgs> tryAfterInstall = x =>
			{
				if (afterInstall != null)
				{
					afterInstall();
				}
			};

			Action<InstallEventArgs> tryBeforeRollback = x =>
			{
				if (beforeRollback != null)
				{
					beforeRollback();
				}
			};

			Action<InstallEventArgs> tryAfterRollback = x =>
			{
				if (afterRollback != null)
				{
					afterRollback();
				}
			};

			installer.InstallService(settings, _arguments, tryBeforeInstall, tryAfterInstall, tryBeforeRollback, tryAfterRollback);
		}
예제 #25
0
 public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
 {
     throw new NotImplementedException();
 }
예제 #26
0
 void ExecutePreActions(InstallHostSettings settings)
 {
     foreach (Action<InstallHostSettings> action in _preActions)
     {
         action(_installSettings);
     }
 }
예제 #27
0
 protected override Installer CreateInstaller(InstallHostSettings settings, string commandLine)
 {
     return(new LsbLinuxHostInstaller(CreateServiceSettings(settings, commandLine), null, CreateServiceLogWriter()));
 }
		protected abstract Installer CreateInstaller(InstallHostSettings settings, string commandLine);
예제 #29
0
		public void InstallService(InstallHostSettings settings, Action beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
		{
			throw new NotImplementedException();
		}
예제 #30
0
        void ConfigureServiceRecovery(InstallHostSettings installSettings)
        {
            var controller = new WindowsServiceRecoveryController();

            controller.SetServiceRecoveryOptions(_settings, _options);
        }
예제 #31
0
        public void InstallService(InstallHostSettings settings, Action<InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action<InstallEventArgs> before = x =>
                    {
                        if (beforeInstall != null)
                        {
                            beforeInstall(settings);
                            installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                            installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                            installer.ServiceProcessInstaller.Account = settings.Credentials.Account;
                        }
                    };

                Action<InstallEventArgs> after = x =>
                    {
                        if (afterInstall != null)
                            afterInstall();
                    };

                Action<InstallEventArgs> before2 = x =>
                    {
                        if (beforeRollback != null)
                            beforeRollback();
                    };

                Action<InstallEventArgs> after2 = x =>
                    {
                        if (afterRollback != null)
                            afterRollback();
                    };

                installer.InstallService(before, after, before2, after2);
            }
        }
예제 #32
0
        public HostServiceInstaller(InstallHostSettings settings)
        {
            _installer = CreateInstaller(settings);

            _transactedInstaller = CreateTransactedInstaller(_installer);
        }
예제 #33
0
        public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback,
                                   Action afterRollback)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                throw new PlatformNotSupportedException("Not running windows");
            }

            using (var installer = new HostServiceInstaller(settings))
            {
                Action <InstallEventArgs> before = x =>
                {
                    if (beforeInstall != null)
                    {
                        beforeInstall(settings);
                        installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                        installer.ServiceProcessInstaller.Account  = settings.Credentials.Account;

                        bool gMSA = false;
                        // Group Managed Service Account (gMSA) workaround per
                        // https://connect.microsoft.com/VisualStudio/feedback/details/795196/service-process-installer-should-support-virtual-service-accounts
                        if (settings.Credentials.Account == ServiceAccount.User &&
                            settings.Credentials.Username != null &&
                            ((gMSA = settings.Credentials.Username.EndsWith("$", StringComparison.InvariantCulture)) ||
                             string.Equals(settings.Credentials.Username, "NT SERVICE\\" + settings.ServiceName, StringComparison.InvariantCulture)))
                        {
                            _log.InfoFormat(gMSA ? "Installing as gMSA {0}." : "Installing as virtual service account", settings.Credentials.Username);
                            installer.ServiceProcessInstaller.Password = null;
                            installer.ServiceProcessInstaller
                            .GetType()
                            .GetField("haveLoginInfo", BindingFlags.Instance | BindingFlags.NonPublic)
                            .SetValue(installer.ServiceProcessInstaller, true);
                        }
                        else
                        {
                            installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                        }
                    }
                };

                Action <InstallEventArgs> after = x =>
                {
                    if (afterInstall != null)
                    {
                        afterInstall();
                    }
                };

                Action <InstallEventArgs> before2 = x =>
                {
                    if (beforeRollback != null)
                    {
                        beforeRollback();
                    }
                };

                Action <InstallEventArgs> after2 = x =>
                {
                    if (afterRollback != null)
                    {
                        afterRollback();
                    }
                };

                installer.InstallService(before, after, before2, after2);
            }
        }
예제 #34
0
        public HostServiceInstaller(InstallHostSettings settings)
        {
            _installer = CreateInstaller(settings);

            _transactedInstaller = CreateTransactedInstaller(_installer);
        }
 void ConfigureServiceRecovery(InstallHostSettings installSettings)
 {
     var controller = new WindowsServiceRecoveryController();
     controller.SetServiceRecoveryOptions(_settings, _options);
 }
예제 #36
0
 public void InstallService(InstallHostSettings settings, Action <InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
 {
     wrappedHost.InstallService(settings, beforeInstall, afterInstall, beforeRollback, afterRollback);
 }
 protected abstract Installer CreateInstaller(InstallHostSettings settings, string commandLine);
 protected override Installer CreateInstaller(InstallHostSettings settings, string commandLine)
 {
     return new LsbLinuxHostInstaller(CreateServiceSettings(settings, commandLine), null, CreateServiceLogWriter());
 }
예제 #39
0
        public void InstallService(InstallHostSettings settings, Action<InstallHostSettings> beforeInstall, Action afterInstall, Action beforeRollback, Action afterRollback)
        {
            using (var installer = new HostServiceInstaller(settings))
            {
                Action<InstallEventArgs> before = x =>
                    {
                        if (beforeInstall != null)
                        {
                            beforeInstall(settings);
                            installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
                            installer.ServiceProcessInstaller.Account = settings.Credentials.Account;

                            // Group Managed Service Account (gMSA) workaround per
                            // https://connect.microsoft.com/VisualStudio/feedback/details/795196/service-process-installer-should-support-virtual-service-accounts
                            if (settings.Credentials.Account == ServiceAccount.User &&
                                settings.Credentials.Username != null &&
                                settings.Credentials.Username.EndsWith("$", StringComparison.InvariantCulture))
                            {
                                _log.InfoFormat("Installing as gMSA {0}.", settings.Credentials.Username);
                                installer.ServiceProcessInstaller.Password = null;
                                installer.ServiceProcessInstaller
                                    .GetType()
                                    .GetField("haveLoginInfo", BindingFlags.Instance | BindingFlags.NonPublic)
                                    .SetValue(installer.ServiceProcessInstaller, true);
                            }
                            else
                            {
                                installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
                            }
                        }
                    };

                Action<InstallEventArgs> after = x =>
                    {
                        if (afterInstall != null)
                            afterInstall();
                    };

                Action<InstallEventArgs> before2 = x =>
                    {
                        if (beforeRollback != null)
                            beforeRollback();
                    };

                Action<InstallEventArgs> after2 = x =>
                    {
                        if (afterRollback != null)
                            afterRollback();
                    };

                installer.InstallService(before, after, before2, after2);
            }
        }