3

I have create a small script file to test.

This my script.bat file.

sc create myService binpath= C:\Users\Admin\Desktop\test.bat start= auto 

This is my test.bat file.

echo "Welcome to Wizard"

Problem Statement

I am unable to start the service from control panel Service section.

I get following error.

[SC] StartService FAILED 1053: The service did not respond to the start or control request in a timely fashion.

That is why I am using nssm.

NOW what happening is that when I run following command on powershell

.\nssm install myService, I dialogue box appears. I give it the path of my script file and click on install service.

After successfull installation of service. I go to control panel -> Service -> click on start against myService but it get paused and following dialog box appears

enter image description here

  1. How can I fix this?
  2. Is there anyother way to do it without doing manual steps and not using third party tool.
  3. I am doing all this on window 10. Do I need any server to perform this task?

NOTE: I cannot use Always up or window scheduler in my case.

13
  • Could be because your script exits immediately. What did you configure for the "action on exit"? Commented Aug 16, 2017 at 6:37
  • @HarryJohnston I have not configure anything yet I am just trying to create a basic file as I am new in batch scripting but in future I wanna run logstash as a background service.
    – Mishi
    Commented Aug 16, 2017 at 6:51
  • Did you see the comment about Windows 10 users needing to use a specific build?: nssm.cc/download -- "Windows 10 Creators Update 2017-04-26: Users of Windows 10 Creators Update should use prelease build 2.2.4-101 to avoid an issue with services failing to start. If for some reason you cannot use that build you can also set AppNoConsole=1 in the registry, noting that applications which expect a console window may behave unexpectedly."
    – andyb
    Commented Aug 16, 2017 at 7:02
  • @andyb In my script I will be taking some input from user by using cmd or powershell then I will create some directories and extract logstash setup and run it as a service. I cannot changes things in registry or use any third party that is the limitation. Do you have any other solution? Or if I write a complete service. Will I still face this issue?
    – Mishi
    Commented Aug 16, 2017 at 7:09
  • 1
    This is not a programming issue and thus doesn't belong on SO. SuperUser is a more appropriate place for questions like this. Commented Aug 16, 2017 at 8:28

3 Answers 3

4

The NSSM behaviour is caused by the script terminating almost instantly. Try the following script:

echo Hello World pause

This should allow the service to start, but you will not necessarily see a console window. Even if you tick 'allow service to interact with desktop', it will not be your desktop that it interacts with!

Windows implements 'session zero isolation' as a security feature, and this essentially prevents services interacting with end user desktops.

In terms of a solution, it's possible to write Windows 'service' applications fairly simply using Visual Studio. It's outside my area of expertise, but based on the Windows applications I'm familiar with, you would generally have a user-mode application running to provide desktop interaction. The user-mode application can interact with services hosted by the service application.

7
  • I have added the pause statement but same behaviour :( I have also tried to run exe file instead of bat but issue is still same. For developing services in VS in not an option right now. I will see the links that you gave me then get back to you. Thanks a lot.
    – Mishi
    Commented Aug 18, 2017 at 5:36
  • Verify the batch file behaves as expected by launching it from Windows explorer (double-click on it). You should see a console window, with the message displayed, followed by a prompt to press a key. Press a key and the console window will close.
    – andyb
    Commented Aug 18, 2017 at 5:39
  • The batch file in which I have added an echo is opening and closes when I press a key but the file in which I am creating a service is not opening. (Script.bat) sc create myService binpath= C:\Users\Admin\Desktop\test.bat start= auto
    – Mishi
    Commented Aug 18, 2017 at 5:43
  • I am using window 10. Do I need a server to create this service?
    – Mishi
    Commented Aug 18, 2017 at 5:44
  • NSSM will work on Win 10. I started a batch file as a service win NSSM on my Win10 laptop yesterday. Depending on how your laptop is configured though, you might not be able to see the console window when it runs.
    – andyb
    Commented Aug 18, 2017 at 5:50
2

Probably this is resolved by now, but in case it helps anyone, what saved the day for me was checking again my input in the arguments field in nssm. I had an extra "-" which created the error. To edit my service, I went via nssm edit <servicename>

0

I would also add on the fix that worked for me. I added "" (quotes) in the argument path and that solved the issue for me.

Not the answer you're looking for? Browse other questions tagged or ask your own question.