我正在尝试让 Windows 服务在您进入会话之前自动启动。
我尝试使用TopShelf
并添加该Start Automatically
方法,但是我启动计算机时服务没有启动。我仍然需要手动启动它。我有什么遗漏吗?
服务开始
public static void RunService() {
var exitCode = HostFactory.Run(x => {
x.Service<SomeService>(s => {
s.ConstructUsing((h) => new SomeService());
s.WhenStarted(t => t.Start());
s.WhenStopped(t => t.Stop());
s.WhenSessionChanged((daemon, host, args) => daemon.SessionChanged(args.SessionId));
});
x.EnableSessionChanged();
x.EnableShutdown();
x.StartAutomatically();
x.RunAsLocalSystem();
});
int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
}