我尝试使用批处理文件来安装Windows服务,让我们把它称为“installservice.bat”。里面的文件我有以下命令:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i ".\MyService.exe"
    pause

当我EXCUTE批处理文件(如运行在Vista管理员)我得到这样的:

Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Win
dows\system32\MyService.exe' or one of its dependencies. The system cannot f
ind the file specified..

在实际的服务位于C:\服务\ MyService.exe。应该采取什么“ \ MyService.exe”的部分是它正常工作?

有帮助吗?

解决方案

为什么不喂InstallUtil的完整路径?

其他提示

以防万一别人来这里为这个错误...当您运行InstallUtil.exe,如果路径为您服务包含空格,应将其用引号括起来。是,这是显而易见的,但它给你,如果你不把错误是没有的。

...误

C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\Users\joeblow\Documents\Visual Studio 2010\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe

...右

C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\Users\joeblow\Documents\Visual Studio 2010\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe"

复制bat文件夹MyService.exe并执行,你不会得到任何错误。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top