Windows – Unable to start service in window 10 by using NSSM

batchbatch fileserviceswindows 10windows-services

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

Window could not start myService service on Local Computer. The service did not return an error. This could be windows error or internal service error.
If problem persist contact to your system administrator.

  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.

Best Answer

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!

Using SysInternals Process Explorer, you will be able to see the NSSM service running with a CMD child process that is executing the script.

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.

Related Question