Windows 服务无法启动,出现一般错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4720388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows service fails to start, with generic error
提问by Chris O
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.
我使用 VS2010 编写了一个简单的 NT 服务,它使用 InstallUtil 安装在我的 XPSP3 开发盒上就好了。但是,当我运行时,net start TestService
出现一般错误: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.
同样的错误也被写入事件系统日志,遗憾的是没有更多关于指定路径net start
不喜欢的详细信息。所以我运行了 Filemon,但没有运气,没有任何输出可以说明我失败的服务。
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.
编辑:感谢大家的提示。DLL 很好,catch 块没有启动,我有 try/catch 块InitializeComponent
和OnStart
方法。下面提到的检查路径的语句是提示。我犯了一个明显的错误,我InstallUtil
从一个 SUBST 驱动器运行了我的二进制文件,由于某种原因,它报告了成功。InstallUtil
从本地路径运行解决了我的问题,该服务现在可以正确启动。
回答by John
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.
首先使用sc qc TestService
验证是否正确安装了服务验证这是一个完整的路径名(以驱动器号开头)并尝试从命令行运行可执行文件。
If the above works, I would try to check permissions on the executable file.
如果上述方法有效,我会尝试检查可执行文件的权限。
回答by Doc
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”
如果您的 ...bin\Release\xxxmyprojxxx.exe 恰好位于网络驱动器上(即使映射到驱动器号),它也不会以 “系统错误 2 ... 系统找不到指定的文件”开头
So copy the dir with the exe (which hopefully includes any dependencies) to a local driveon the machine (san or internal drive), NOTa mapped network share/drive.
因此,将带有 exe 的目录(希望包含任何依赖项)复制到机器上的本地驱动器(san 或内部驱动器),而 不是映射的网络共享/驱动器。