The service process could not connect to the service controller
Asked Answered
B

6

21

Hi I am trying to write just a quick demo service. I am following the tutorial from MSDN here:

http://msdn.microsoft.com/en-us/library/zt39148a.aspx

So this tutorial basically sets up an basic service that writes to the event log. It also configures the installation and adds a setup project. So I have tried the installation on a couple of computers, one running Server 2008 R2 and one running Windows 7.

Basically what happens is the setup runs fine, but the service does not show up in the service list. I also checked the event log and receive an error with a description of:

"The service process could not connect to the service controller"

However there is no other information about the error. Does anyone have any idea how to get the service to show up in the service list and to run? Thanks.

One other item I could mention is that the custom log for the service is created however there are no entries.

Bucci answered 8/1, 2011 at 17:43 Comment(0)
B
4

Problem solved. I didn't follow the last part of the tutorial for adding a custom action :) I thought at first it was optional however it appears that is the final part of installing the service. Works perfect now.

Bucci answered 8/1, 2011 at 21:7 Comment(4)
can you link the tutorial? I'm having the same issuePhysiological
The tutorial is linked in the question.Imbricate
Which action? The page learn.microsoft.com/en-us/dotnet/framework/windows-services/… doesn’t have term “custom action”.Blintze
I downvoted the answer because it does not specify the exact action or part of the tutorial which had to be implemented.Knavery
K
18

The message "Service cannot be started. The service process could not connect to the service controller" is logged in the event log everytime you attempt to run a windows service from Visual Studio. Unlike most projects you create in Visual Studio, Windows Service projects cannot be run directly from the development environment by pressing F5. See the following msdn link http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx

Krenn answered 20/1, 2012 at 15:26 Comment(0)
B
4

Problem solved. I didn't follow the last part of the tutorial for adding a custom action :) I thought at first it was optional however it appears that is the final part of installing the service. Works perfect now.

Bucci answered 8/1, 2011 at 21:7 Comment(4)
can you link the tutorial? I'm having the same issuePhysiological
The tutorial is linked in the question.Imbricate
Which action? The page learn.microsoft.com/en-us/dotnet/framework/windows-services/… doesn’t have term “custom action”.Blintze
I downvoted the answer because it does not specify the exact action or part of the tutorial which had to be implemented.Knavery
H
4

You need to add an Installer to your service.

Go to the designer view of your service. click on the "Add Installer" link. This adds objects that are mandatory for the service installation.

enter image description here

Last thing is to make sure you run your installutil.exe with Administrator privileges.

enter image description here

Homopolar answered 26/7, 2014 at 17:57 Comment(1)
Similar answer here: #12362955Homopolar
C
0

Just uncheck "Enable the Visual Studio hosting process" works for me!

Consalve answered 24/6, 2015 at 4:17 Comment(0)
G
0

The Service Control Manager (abbreviated SCM, usually located at C:\Windows\System32\services.exe) is the executable that actually loads the installed Windows Service executables. That is why logs sometimes appear in the System32 directory when initially installed, as discussed here. There are many ways to install a Windows service. One way is to use an additional host application layer, such as Non-Sucking Service Manager (NSSM). In this case, SCM loads an assembly from NSSM, which in turn loads the desired service executable. If using InstallUtil, you might need a line of code like this: System.ServiceProcess.ServiceBase.Run(servicesToRun);, whereas if you are using an additional application hosting layer, like NSSM, you can just go right into your custom service logic without calling the ServiceBase. If you do call the ServiceBase when using NSSM, you may get the error message in the title of this posted question.

Grapheme answered 8/5 at 22:42 Comment(0)
H
0

I faced the same issue.Even I tried to make changes from console application to Windows application. But it didnt work. Because, windows services cannot run as a normal application inside IDE. SCM interaction will happen in the services side so try installing the service to the SCM. After installation if you face the same issue try attaching the process to the exe and start debugging from the IDE.

CMD for installing a service

New-Service -Name "ServiceName" -BinaryPathName "Path/ServiceName.exe"
Hearsh answered 14/6 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.