1

我正在尝试让 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());
        }
4

1 回答 1

1
  1. 检查服务控制面板应用程序(“services.msc”)并确认您的服务的启动类型为“自动”。
  2. 使用事件查看器,检查Windows 日志 > 应用程序区域以获取来自您的服务的消息。也许它在启动时开始但很快崩溃或停止。
  3. 使用事件查看器,检查事件日志的Windows 日志 > 系统区域是否有启动服务的错误。查看来源为“服务控制管理器”的记录。

有关其他建议,请参阅“为什么我的 Windows 服务在启动时不启动? ”。

于 2019-07-03T10:35:17.137 回答