0

I have registered a custom service called customService with Automatic (Delayed Start) as its Startup Type option. It was created using NSSM with the following command

nssm install customService

It runs a simple batch file, customService.bat containing two simple windows command

cd D:\To\Custom\Path
type NUL > 1.txt

What the service does is run this batch file which would create an empty text file, 1.txt in \To\Custom\Path folder.

Problem

When I shutdown and boot up my machine, no 1.txt is created. However, in services.msc, it shows customService status as Running. Why is this happening?


What I have discovered

  1. When the problem occurs, in Event Logs > Windows logs > Application, there is no error produced. The last recorded log is from MSSQLSERVER service with the Level of Information and Event ID of 8128. It has been exactly 15 minutes passed.
  2. In services.msc > customService Status shows Running. When I right-click it, I'm allowed at least 3 options: Stop, Pause, and Restart. The service runs successfully (i.e., 1.txt created) when I clicked Restart.
  3. In services.msc > customService properties > Dependencies tab, it shows no Dependencies
  4. I have absolutely no problems when I restart my computer ( i.e., 1.txt is created.)

Windows Specs

I have Windows 10 Version 1607 (OS Build 14393.576) as shown when running winver command. Also, I have all updates installed.

2 Answers 2

1

How did you define the service? Documentation suggests you should have a run commands like:

nssm set UT2003 Application C:\games\ut2003\System\UCC.exe
nssm set UT2003 AppDirectory C:\games\ut2003\System

(Substituting in the path to your batch file)

In any case, NSSM sounds like overkill here. Why not just use Task Scheduler?

3
  • That is another way to do it. However, documentation also suggests the use of GUI. How is it different? I.e., when running nssm install customService, a GUI pops up enabling me to set Application path and AppDirectory. Jan 9, 2017 at 5:33
  • Anyway, +1 for the suggestion to use Task Scheduler. It lead me to believe this is due to Log In issue after trying it out with Task Scheduler. Jan 9, 2017 at 6:14
  • I agree with @ernie, NSSM isn't right tool here. Concept of service is continuously running program, such as web server for example. If you need to do just a single shot, it IMHO a task for Task Scheduler
    – Alex
    Jan 9, 2017 at 6:51
0

Disclaimer: This is just a crude workaround that I hope can be useful to others, not a fix. The workaround is use Task Scheduler instead.

I have deep suspicion this problem is due to User Account issues although I don't have any concrete written evidence for that

I arrived at this suspicion when I tried to use Task Scheduler to launch my .bat file instead of using a Service. When I set it to Run on system startup, after booting up, there was a Warning in History tab of my created task saying Task Scheduler did not launch task because user "(NONE)" was not logged on when the launching conditions were met. Hence the reason why I think this problem is somehow linked to User Account issues although I may be wrong because no such warning/error occur in Event logs when I used Services to launch my batch file.

So I set it to run after logged on and there have been no problems running this task on startup. I'm not sure if this kind of setting can also be set for Services. This could also be the reason why people tend to use the setting Automatic (Delayed Start)

Note that setting this task to run after logged on will make it run when you signed in having signed out. It will not run when you signed in after locking your computer,

1
  • If you want to run some task on system startup you need to create privileged user and setup him up in Task Scheduler as user how going to run this task. Well if computer isolated from wild internet and strange people, you can run your task as a SYSTEM user, but it really a bad idea if it isn't.
    – Alex
    Jan 9, 2017 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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