11

我正在尝试使用批处理文件安装 Windows 服务,我们称之为“installservice.bat”。在文件中,我有以下命令:

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

当我执行批处理文件(在 Vista 上以管理员身份运行)时,我得到以下信息:

初始化安装时发生异常:
System.IO.FileNotFoundException:无法加载文件或程序集 'file:///C:\Win
dows\system32\MyService.exe' 或其依赖项之一。系统不能
找到指定的文件..

实际服务位于 C:\Services\MyService.exe。“.\MyService.exe”部分应该是什么才能正常运行?

4

3 回答 3

10

以防万一其他人出现此错误...当您运行 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"
于 2012-03-09T18:06:45.413 回答
3

为什么不直接提供 InstallUtil 完整路径?

于 2009-08-14T08:01:27.007 回答
0

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

于 2011-10-14T11:06:33.267 回答