安装了新的 Windows 服务,无法启动:“系统错误 2 ... 系统找不到指定的文件" [英] New Windows Service installed, fails to start: "System error 2 ... system cannot find the file specified"

查看:53
本文介绍了安装了新的 Windows 服务,无法启动:“系统错误 2 ... 系统找不到指定的文件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功安装了其他几个自定义的 .Net Windows 服务.我最近写的一个新的与其他的非常相似,虽然它安装没有错误 - 在使用服务控制器启动它时,它无法启动并显示错误对话框:系统错误 2 ... 系统找不到指定的文件.

I have installed several other custom .Net windows services successfully. A new one I had recently written was very similar to the others and while it installed without error - on starting it with the service controller it failed to start with the error dialog: System error 2 ... system cannot find the file specified.

经过时间和惊愕之后,我能想到的唯一与此服务显着不同的是路径和可执行文件名称至少比我的任何其他服务长 10 个字符.缩短路径和 .exe 名称并重新安装后,服务运行良好:没有错误!我只能假设我以前的路径或服务或 .exe 名称太长.

After time and consternation, the only thing I could think of that was significantly different about this service was that the path and executable name were at least 10 characters longer than any of my other services. On shortening both the path and .exe name and re-installing, the service ran fine: no error! I can only assume my previous path or service or .exe name was too long.

另外,值得一提的是,我使用了一些内置于我的 exe 中的借用服务驱动程序"代码,通过 win API 调用处理服务控制器的安装/卸载.可能是该服务驱动程序模块中隐藏了字符限制.

Also, It would be pertinent to mention I had used some borrowed "service driver" code built in to my exe to handle the install/uninstall of the service to the service controller via win API calls. It could be a character limit was hidden within that service driver module.

我找不到任何与 Windows 相关的文档来确认我是否超出了路径或服务名称的系统绑定字符限制.如果时间允许,我将深入了解服务驱动程序,看看是否是问题所在.同时,我欢迎任何见解.

I could not find any windows related docs to confirm if there is a system bound character limit to a path or service name that I had exceeded. I will dig in to the service driver when time permits and see if that turns out to be the problem. Meanwhile I welcome any insights.

推荐答案

我尝试了一些测试服务,发现不是任何属性的长度导致我的问题(系统错误 2 ... 系统找不到文件指定")开始.我的内置服务安装程序使用三个属性:ServiceName、ServiceTitle、ServiceDescription.在安装时,我发现它将完整的服务路径写入注册表,但它不只是采用实际的 exe(程序集)名称,它使用 ServiceName 属性来构建路径!我的问题是 ServiceName 和程序集名称不匹配,因此找不到文件.我使用了一个 powershell 注册表查询来公开路径,最后注意到那里的不匹配.当我第一次注意到这个问题时,我没有注意到当我缩短服务名称时——我只是使用了没有 .exe 的程序集名称,这才是真正修复它的方法,而不是简单地缩短它.

I experimented with some test services and found it was not the length of any property that caused my problem ("System error 2 ... system cannot find the file specified") to begin with. My built in service installer uses three properties: ServiceName, ServiceTitle, ServiceDescription. On installing, I found that it writes full service path to the registry, but it doesn’t just take the actual exe (assembly) name, it uses the ServiceName property to build the path! My issue was that the ServiceName and assembly name didn’t match, hence file not found. I used a powershell registry query to expose the path and finally noticed the mismatch from there. When I first noticed the problem I had not noticed that when I shortened the service name from whatever it was – that I just used the assembly name without the .exe and that is what actually fixed it, not simply shortening it.

这篇关于安装了新的 Windows 服务,无法启动:“系统错误 2 ... 系统找不到指定的文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆