The service process could not connect to the servi

2020-02-13 07:43发布

问题:

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.

回答1:

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



回答2:

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.



回答3:

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.



回答4:

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



标签: c# service