Installing Windows Service with batch file?

Banshee picture Banshee · Sep 28, 2012 · Viewed 31.5k times · Source

I have the following in a bat file :

@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.

The problem is that it even if the bat file is located in the same folder as the My.WindowsService.exe it will try to look for it in C:\Windows\System32.....

How do I solve this?

Answer

Banshee picture Banshee · Nov 9, 2012

This is how it is solved :

@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.