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"
"%~dp0nssm64.exe" install MyService "%~dp0test.bat">NUL 2>&1&&"%~dp0nssm64.exe" Start MyService
. As for your batch file, you need to delete the comment above and add the content as properly formatted code, (using the[{}]
button), to your question by editing it.