Reputation: 1428
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.
Upvotes: 22
Views: 98782
Reputation: 1
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"
Upvotes: 0
Reputation: 606
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.
Upvotes: 1
Reputation: 11
Just uncheck "Enable the Visual Studio hosting process" works for me!
Upvotes: 0
Reputation: 1165
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.
Last thing is to make sure you run your installutil.exe with Administrator privileges.
Upvotes: 4
Reputation: 887
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
Upvotes: 18
Reputation: 1428
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.
Upvotes: 5