10

我在 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 中查找它.....

我该如何解决这个问题?

4

4 回答 4

13

这是如何解决的:

@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.
于 2012-11-09T08:16:50.303 回答
6

根据我发现的几篇文章,将绝对路径传递给您的服务就是您想要的。例如:

{...Path_To_.NET_Framework...}\InstallUtil C:\MyFolder\My.WindowsService.exe

如果您想要动态生成的路径,您可以在批处理文件中使用类似的内容获取当前目录:

set CURDIR=%CD%
{...Path_To_.NET_Framework...}\InstallUtil %CURDIR%\My.WindowsService.exe

参考:

于 2012-09-28T15:52:52.787 回答
2

它太旧了,但对我很有用......我做了一些改变。

我的服务是手动启动的,所以在批处理中我包含了启动命令,然后打开控制台检查已安装的服务。

@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.
于 2013-07-30T15:57:00.017 回答
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 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.
于 2019-01-17T05:37:42.027 回答