private void SetServiceRunAs(HostConfigurator x) { switch (ServiceRunAs) { case ServiceRunAs.LocalService: x.RunAsLocalService(); break; case ServiceRunAs.LocalSystem: x.RunAsLocalSystem(); break; case ServiceRunAs.NetworkService: x.RunAsNetworkService(); break; case ServiceRunAs.Prompt: x.RunAsPrompt(); break; case ServiceRunAs.UserLogin: x.RunAs(UserName, UserPassword); break; } }
public void ApplyTo(HostConfigurator configurator) { configurator.RunAs(_username, _password); }
/// <summary> /// Configure /// </summary> /// <param name="hostCfg"></param> /// <returns></returns> public HostConfigurator Configure(ref HostConfigurator hostCfg) { #region 设置运行模式 switch (RunAs) { case ServiceAccount.LocalService: hostCfg.RunAsLocalService(); break; case ServiceAccount.LocalSystem: hostCfg.RunAsLocalSystem(); break; case ServiceAccount.NetworkService: hostCfg.RunAsNetworkService(); break; case ServiceAccount.User: hostCfg.RunAs(UserName, Password); break; default: hostCfg.RunAsPrompt(); break; } #endregion #region 设置启动模式 switch (StartMode) { case HostStartMode.AutomaticDelayed: hostCfg.StartAutomaticallyDelayed(); break; case HostStartMode.Disabled: break; case HostStartMode.Manual: hostCfg.StartManually(); break; default: hostCfg.StartAutomatically(); break; } #endregion #region 设置服务基础信息 hostCfg.SetServiceName(ServiceName); hostCfg.SetInstanceName(InstanceName); hostCfg.SetDescription(ServiceDescription); hostCfg.SetDisplayName(ServiceDisplayName); #endregion return(hostCfg); }
/// <summary> /// Configures the specified configuration. /// </summary> /// <param name="config">The configuration.</param> private void Configure(HostConfigurator config) { try { config.Service <ISelfUpdatableService>(service => { service.ConstructUsing(settings => selfUpdatableService); service.WhenStarted((s, hostControl) => { s.Start(); return(true); }); service.AfterStartingService(() => { updater?.Start(); }); service.WhenStopped(s => { s.Stop(); }); }); config.StartAutomatically(); config.EnableShutdown(); config.UseAssemblyInfoForServiceInfo(HostAssembly); if (promptForCredentialsWhileInstalling) { config.RunAsFirstPrompt(); } else { if (TypeRunAs == RunAS.LocalSystem) { config.RunAsLocalSystem(); } else if (TypeRunAs == RunAS.LocalService) { config.RunAsLocalService(); } else if (TypeRunAs == RunAS.NetworkService) { config.RunAsNetworkService(); } else if (TypeRunAs == RunAS.SpecificUser) { if (string.IsNullOrEmpty(serviceLogin)) { throw new Exception("Service Login not specified"); } if (string.IsNullOrEmpty(servicePassword)) { throw new Exception("Service Password not specified"); } config.RunAs(serviceLogin, servicePassword); } } config.AddCommandLineSwitch("squirrel", _ => { }); config.AddCommandLineDefinition("firstrun", _ => Environment.Exit(0)); config.AddCommandLineDefinition("obsolete", _ => Environment.Exit(0)); config.AddCommandLineDefinition("updated", version => { config.UseHostBuilder((env, settings) => new UpdateHostBuilder(env, settings, version, withOverlapping)); }); config.AddCommandLineDefinition("install", version => { config.UseHostBuilder((env, settings) => new InstallAndStartHostBuilder(env, settings, version)); }); config.AddCommandLineDefinition("uninstall", _ => { config.UseHostBuilder((env, settings) => new StopAndUninstallHostBuilder(env, settings)); }); } catch (Exception ex) { Log.Error("Exception : ", ex); } }
public override void Configure(HostConfigurator conf) { conf.RunAs(Username, Password); }