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

时间:2010-07-14 07:27:32

标签: .net windows-services topshelf

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

https://github.com/Topshelf/Topshelf

1 个答案:

答案 0 :(得分:7)

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);