Windows 服务无法启动,出现一般错误
我使用 VS2010 编写了一个简单的 NT 服务,它确实可以使用 InstallUtil 安装在我的 XPSP3 开发盒上。但是,当我运行 net start TestService
时,出现一般错误:由于以下错误,TestService 服务无法启动: 系统找不到指定的路径。
同样的错误也会写入事件系统日志,遗憾的是没有更多关于 net start
不喜欢哪个指定路径的详细信息。所以我运行了 Filemon,但运气不佳,没有任何输出可以揭示我失败的服务。
该服务在本地服务帐户下运行。
有什么调试这个问题的技巧吗?
编辑:感谢大家的提示。 DLL 很好,catch 块没有启动,我在 InitializeComponent
和 OnStart
方法周围有 try/catch 块。下面提到的检查路径的语句就是提示。我犯了一个明显的错误,我从 SUBST 驱动器上的二进制文件上运行 InstallUtil
,由于某种原因报告成功。从本地路径运行 InstallUtil
解决了我的问题,服务现在可以正确启动。
I wrote a trivial NT service using VS2010 and it does install on my XPSP3 dev box just fine, using InstallUtil. However when I run net start TestService
I get a generic error:The TestService service failed to start due to the following error:
The system cannot find the path specified.
This same error is also written to the Event System Log, unfortunately with no more details as to which specified path net start
didn't like. So I ran Filemon, but no luck there, none of the output could shed any light on my failing service.
The service runs under the Local Service account.
Any tips for debugging this problem?
EDIT: Thanks to all for the tips. DLLs were fine, catch blocks not kicking in, I had try/catch blocks around InitializeComponent
, and OnStart
methods. The below-mentioned statements of checking the path was the tip-off. I've made an obvious mistake, I had run InstallUtil
on my binary from a SUBST'ed drive, which reported success for some reason. Running InstallUtil
from a local path fixed my problem, the service now starts correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先使用
sc qc TestService
验证服务是否已正确安装验证这是否是完整路径名(以驱动器号开头)并尝试从命令行运行可执行文件。
如果上述方法有效,我会尝试检查可执行文件的权限。
First verify that the service is installed properly using
sc qc TestService
Verify that this is a full path name (starting with drive letter) and try to run the executable from the command line.
If the above works, I would try to check permissions on the executable file.
如果您的 ...bin\Release\xxxmyprojxxx.exe 恰好位于网络驱动器上(即使映射到驱动器号),它不会以“系统错误 2 ...系统找不到该文件”开头 因此,将带有 exe 的目录
(希望包含任何依赖项)复制到计算机上的本地驱动器(san 或内部驱动器),不是映射的网络共享/驱动器。
If your ...bin\Release\xxxmyprojxxx.exe happens to be on a network drive (even if mapped to a drive letter), it will NOT start with the “System error 2 ... system cannot find the file specified”
So copy the dir with the exe (which hopefully includes any dependencies) to a local drive on the machine (san or internal drive), NOT a mapped network share/drive.