【问题标题】:Windows service doesn't start on windows server 2019Windows 服务无法在 Windows Server 2019 上启动
【发布时间】:2022-11-22 13:05:07
【问题描述】:

我有一个包含 3 个 Windows 服务的项目,这些服务运行良好,然后出于业务需要,我们需要从 Windows Server 2008 迁移到 Windows Server 2019。

我面临的问题是:

当我安装服务时,它没有启动并返回错误事件查看器:

无法启动服务。 System.Security.SecurityException: 未找到来源,但无法搜索到部分或所有事件日志。无法访问的日志:安全、状态。

我搜索了这个问题,找到了很多答案(比如this),但对我没有帮助。

我安装了服务管理员身份命令行使用安装工具.

然后打开了注册表编辑器并给用户网络服务完全控制路径如下:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog

然后我检查路径中服务的子项:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application

而且,它存在。

我的代码与事件簿:

 public class EventViewer
{
    public static void WriteEvent(string ServiceName, string msg, EventLogEntryType _EventLogEntryType)
    {

        EventLog eventLog = new EventLog();
        eventLog.Source = ServiceName;
        eventLog.Log = "Application";
        ((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit();
        if (!EventLog.SourceExists(eventLog.Source))
        {
            EventLog.CreateEventSource(eventLog.Source, eventLog.Log);
        }
        ((System.ComponentModel.ISupportInitialize)(eventLog)).EndInit();
        eventLog.WriteEntry(msg, _EventLogEntryType);
    }
}

这事件查看器给我异常行,它指的是:

((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit();

我尝试使用调试我机器上的服务视觉工作室 2019,但也给我同样的错误,服务不会使用“附加到进程”开始调试。

【问题讨论】:

    标签: exception windows-services event-log windows-server-2019


    【解决方案1】:

    我认为问题出在扫描注册表以检查事件源是否存在时。 https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.createeventsource?view=dotnet-plat-ext-6.0

    根据 Microsoft,该帐户需要管理权限才能执行此任务。 我还看到在 Windows 2019 的“EventLog”下有一个名为“state”的新注册表配置单元,与其他配置单元相比,它的访问权限较少。

    使用进程监视器进行调试,看看您是否在该配置单元中被拒绝访问。

    【讨论】:

    • 以管理员身份添加服务帐户对我有用。谢谢。
    【解决方案2】:

    我可以知道你如何添加电子服务帐户吗?我也遇到类似的问题。谢谢。

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 2021-02-27
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多