我在bat文件中有以下内容:
@ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Installing IEPPAMS Win Service...
echo ---------------------------------------------------
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil My.WindowsService.exe
echo ---------------------------------------------------
pause
echo Done.
问题是,即使bat文件与My.WindowsService.exe位于同一文件夹中,它也会尝试在C:\ Windows \ System32中查找它....
我该如何解决这个问题?
答案 0 :(得分:10)
这是如何解决的:
@ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Installing IEPPAMS Win Service...
echo ---------------------------------------------------
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil "%~dp0My.WindowsService.exe"
echo ---------------------------------------------------
pause
echo Done.
答案 1 :(得分:5)
根据我发现的几篇文章,将绝对路径传递给您的服务是您想要的。例如:
{...Path_To_.NET_Framework...}\InstallUtil C:\MyFolder\My.WindowsService.exe
如果您想要一个动态生成的路径,您可以在批处理文件中使用类似的内容获取当前目录:
set CURDIR=%CD%
{...Path_To_.NET_Framework...}\InstallUtil %CURDIR%\My.WindowsService.exe
参考文献:
答案 2 :(得分:1)
它太旧但对我有用......我做了一些改变。
我的服务手动启动,因此,在批处理中我包含了启动命令,然后打开控制台以检查已安装的服务。
@ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Installing MyService Win Service...
echo ---------------------------------------------------
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil /i "%~dp0MyService.exe"
net start MyService
services.msc
echo ---------------------------------------------------
pause
echo Done.
答案 3 :(得分:0)
@ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Instalar Servicio......
echo ---------------------------------------------------
InstallUtil /i "%~dp0WindowsService1.exe"
echo ---------------------------------------------------
pause
echo Done.
@ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
echo Desintalar Servicio...
echo ---------------------------------------------------
InstallUtil /u "%~dp0WindowsService1.exe"
echo ---------------------------------------------------
pause
echo Done.