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

如何将TopShelf配置为作为ServiceAccount.NetworkService运行服务?,.net,windows-services,topshelf,.net,Windows Services,Topshelf,如何将TopShelf配置为作为ServiceAccount.NetworkService运行服务 TopShelf的新位置已更新为允许此行为的补丁 RunConfiguration cfg = RunnerConfigurator.New(x => { x.AfterStoppingTheHost(h => { Console.WriteLine("AfterStop called invoked, services are stopping"); }); x.C

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


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);
RunConfiguration cfg=RunnerConfigurator.New(x=>
{
x、 AfterStoppingTheHost(h=>{Console.WriteLine(“调用了AfterStop,服务正在停止”);});
x、 配置服务=>
{
s、 命名为(“tc”);
s、 HowToBuildService(name=>newtowncrier());
s、 开始时(tc=>tc.Start());
s、 停止时(tc=>tc.Stop());
});
//作为网络服务帐户运行
x、 RunAsNetworkService();
x、 SetDescription(“样本Topshelf主机”);
x、 SetDisplayName(“Stuff”);
x、 SetServiceName(“stuff”);
});
主机(cfg,args);

您还可以使用命令行选项覆盖配置,例如--networkservice、-localservice或--interactive,以便在安装服务时提示输入用户名/密码。