Archive: How to create a service EXE which calls a BATCH file.


How to create a service EXE which calls a BATCH file.
I went to http://nsis.sourceforge.net/NSIS_Service_Lib and included "servicelib.nsh".
I have a batch (.BAT) file which I wanted to add as a Windows Service.
I have written an EXE, Its code is given below:

outfile "Gateway-Start.exe"

!include servicelib.nsh
!define InstallDir "Gateway"
InstallDir "$PROGRAMFILES\${InstallDir}"

# create a default section.
section
call executeGateway
setOutPath $INSTDIR
sectionEnd

Function executeGateway
# I tried using EXEC but no success.
# Exec "$INSTDIR\bin\gateway.start.bat";
ExecShell "open" "$INSTDIR\bin\gateway.start.bat";
FunctionEnd

If I double click above EXE the gateway BATCH files starts, but if I add this EXE as a Windows Service the BATCH file executes but the status in services.msc never changes to STARTED.

Its very urgent please help and thanks in advance.


Maybe it's because the exe closed itself after the batch is started and the batch is closing as well after the eof is reached?


How to create a service EXE which calls a BATCH file.
The BATCH file executes successfuly as I do see java.exe instance alive in Task Manager.

But NSIS EXE gets closed after I receive a PopUp saying "Error 1053: The service did not respond to the start or control request in timely fashion" in my services.msc window.

Even if the NSIS EXE gets closed the java.exe (the BATCH file) still persist in Task Manager which is correct.

The problem is, in services.msc the status for my service is not saying STARTED, it just says STARTING... and then no status.

Please help.


Erm... it's java that is running and not the batch.
Windows is only watching the file, the service is associated to (like service.exe).

if the service is the batch file itself, try starting java with "Start /W". This will keep the batch running until java is closed.
Maybe the msc will then tell the correc status, but i can't say this for sure because i never build a service on a batch.
But i did serveral times using VB.

Using VB makes own serices easy because i can watch the started process (like java) and if it was closed, stop the service or restart the program. Maybe this is an option for you?
You can use NSiS for such a program too, but in my opinion it's harder with NSiS to get the pid of a specific process.

Edit:
Forgot to mention that the service exe, which starts the program, is made to stay in memory. Won't work else.