Windows 服务无法在启动时启动
在开始正文之前,请注意我已经尝试过以下操作:
- 设置服务依赖
- 项 设置延长的超时
现在,话虽如此,您可能会猜到我的问题是什么: 我的 Windows 服务无法启动时启动,但我可以从服务管理器手动启动它。事件日志显示它确实尝试在启动时启动,但未能及时响应。
该服务没什么特别的,因为它只访问 SOAP 端点,运行一些系统命令,并运行一些 WMI 查询。我已将该服务设置为依赖于 DNS 服务和 WMI 服务,但它仍然无法启动(超时),这告诉我有其他原因阻止它运行。
我正在使用 NSIS SimpleSC 插件注册该服务,并使用以下选项:
Service Type: SERVICE_WIN32_OWN_PROCESS
Start Type: SERVICE_AUTO_START
Dependencies: Winmgmt, Netman, Eventlog, Dnscache
User Name: LocalSystem
我缺少什么?
Before I get into the text of this, please be aware that I have already tried the following:
- Setting the service dependencies
- Setting an extended timeout
Now, that having been said, you can probably guess what my problem is: My Windows service is failing to start on boot, yet I can start it just fine manually from the services manager. The event log shows that it did attempt to start on boot, but it failed to respond in a timely manner.
The service is nothing extraordinary, in that it only hits a SOAP endpoint, runs some system commands, and runs some WMI queries. I have set the service to depend on the DNS service and the WMI service, yet it's still failing to start (timing out), which tells me something else is keeping it from running.
I am registering the service using the NSIS SimpleSC plugin, using the following options:
Service Type: SERVICE_WIN32_OWN_PROCESS
Start Type: SERVICE_AUTO_START
Dependencies: Winmgmt, Netman, Eventlog, Dnscache
User Name: LocalSystem
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在您的服务中使用 SetServiceStatus 给它一些时间。请记住,加载顺序很重要。
Try using SetServiceStatus in your service to give it some time. And bear in mind, loading order is important.
事实证明,这个问题的级别低于启动命令之类的问题。它与我在服务构造函数中的一些初始化代码有关。一旦我重构它以将该代码移到构造函数之外,一切都运行良好。
感谢@AljoshaBre 和@Peter K. 的帮助。
Turns out this issue was at a level lower than the start order or that sort of thing. It had to do with some initialization code I had in my service's constructor. Once I refactored it to move that code outside of the constructor, all was working well.
Thank you to @AljoshaBre and @Peter K. for their help.