【问题标题】:How to configure TopShelf to run a service as ServiceAccount.NetworkService?如何配置 TopShelf 以将服务作为 ServiceAccount.NetworkService 运行?
【发布时间】:2010-07-14 07:27:32
【问题描述】:

如何配置 TopShelf 以作为 ServiceAccount.NetworkService 运行服务?

https://github.com/Topshelf/Topshelf

【问题讨论】:

    标签: .net windows-services topshelf


    【解决方案1】:

    TopShelf 的新位置http://github.com/Topshelf/Topshelf 已更新为允许此行为的补丁。

    RunConfiguration cfg = RunnerConfigurator.New(x =>
    {
        x.AfterStoppingTheHost(h => { Console.WriteLine("AfterStop called invoked, services are stopping"); });
    
        x.ConfigureService<TownCrier>(s =>
        {
            s.Named("tc");
            s.HowToBuildService(name=> new TownCrier());
            s.WhenStarted(tc => tc.Start());
            s.WhenStopped(tc => tc.Stop());
        });
        // Running as the network service account
        x.RunAsNetworkService();
    
        x.SetDescription("Sample Topshelf Host");
        x.SetDisplayName("Stuff");
        x.SetServiceName("stuff");
    });
    
    Runner.Host(cfg, args);
    

    【讨论】:

    • 您还可以使用命令行选项覆盖配置,例如 --networkservice、--localservice 或 --interactive,以便在安装服务期间提示输入用户名/密码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 2017-04-08
    • 1970-01-01
    • 2019-09-13
    • 2018-07-13
    • 1970-01-01
    • 2015-08-13
    相关资源
    最近更新 更多