Search code examples
windows-servicesbatch-fileinstallutil

Installing Windows Service with batch file?


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?


Solution

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