2

I built Topshelf sample application, (Version 4.0.1) the one with the TimedEvents that just write to console. Could install and run ok as Admin. When installing as NetworkService (trying to run with fewer privileges for better security practices) got error:

[Success] Name Stuff, [Success] Description Sample Topshelf Host, [Success] ServiceName Stuff Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000 Topshelf.Hosts.StartHost Error: 0 : The service failed to start., System.InvalidOperationException: Cannot start service Stuff on computer '.'. ---> System.ComponentModel.Win32Exception: Access is denied --- End of inner exception stack trace --- at System.ServiceProcess.ServiceController.Start(String[] args) at System.ServiceProcess.ServiceController.Start() at Topshelf.Runtime.Windows.WindowsHostEnvironment.StartService(String serviceName, TimeSpan startTimeOut) at Topshelf.Hosts.StartHost.Run()

In this case, there is no input or output file, so access permissions to other files should not be the problem.

Travis
  • 10,444
  • 2
  • 28
  • 48
mdev
  • 71
  • 1
  • 6

1 Answers1

3

Turns out that in this case, even when there are no file permissions to input/output to take care of, the executable also needs appropriate permissions set. The setting needs to be "read+execute".

This problem is a variation of this answer here: Cannot Start Windows Service in NetworkService account

Following the steps there, and setting the permissions on the executables (in my case the bin/debug folder) and the topshelf service runs fine.

[Success] Name Stuff, [Success] Description Sample Topshelf Host, [Success] ServiceName Stuff Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000 The Stuff service was started.

So, even when using Topshelf, you still have to make sure everything else is set up appropriately for the service to run.

I would recommend this approach over registry editing, or just running all services as LocalSystem as I have seen recommended in other answers to similar permissions issues with windows services.

Community
  • 1
  • 1
mdev
  • 71
  • 1
  • 6