Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run batch file as a windows service through nssm

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

enter image description here

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"
like image 394
Henrik Avatar asked Dec 06 '25 18:12

Henrik


1 Answers

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.

like image 137
timpokorny Avatar answered Dec 09 '25 21:12

timpokorny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!