I'm trying to run batch file as a windows service through nssm which will run an exe file if it is not runned. My code to create service from batch file
CALL "%~dp0nssm64.exe" install MyService "%~dp0test.bat"
CALL "%~dp0nssm64.exe" start MyService
(%~dp0 is the path of the batch file I am running)
I have no problems to creating service, but with starting it. I get the following message while trying to start it manually

In the windows event viewer there is a warning with the message "Service MyService ran for less than 1500 milliseconds. Restart will be delayed by 256000 milliseconds."
So how should I solve the problem? any idea? Thank you
Edit
Here is the batch file code:
tasklist /FI "IMAGENAME eq SomeEXE.exe" 2>NUL | find /I /N "SomeEXE.exe">NUL
if "%ERRORLEVEL%"=="0" echo Program is running
if "%ERRORLEVEL%"=="1" start "" "%~dp0SomeEXE.exe"
I just encountered pretty much the same error. I have a batch file that starts a Java application.
Execution line in the batch file was:
start javaw -jar "%APP_HOME%\lib\app.jar" %*
I just fixed it by removing the "start". No more insight into why, but that worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With