Windows Service application in c#

非 Y 不嫁゛ 提交于 2021-01-28 12:12:54

问题


I have created a Windows Service application using c#. I have followed the steps from this msdn documentation but the service is not listing in the services section in Computer -> Manage -> Service pane.

Am I missing something? its Windows 7.

Want to run my service to check the functionality.

Thanks


回答1:


You need to install your service for the Windows Service Control Manager (SCM) to know about it (by virtue of a resulting registry entry).

You have (at least) two options to do this:

sc create "SERVICENAME" binpath = "C:\whatever\Service.exe"

installutil "C:\whatever\Service.exe"

For sc create, any command prompt should do. For installutil, Visual Studio Command Prompt is the easiest way to run it - since the VS Command Prompt's PATH environment variable makes using .NET command-line tools easy; and your service needs to implement a service (un)installer in my experience.

After you install and reality check your service, you will almost certainly want to uninstall it at some point - e.g. to then install a final version of it in a non-dev location or to just clean up dev service entries littering your list of installed services. You have corresponding options in sc delete and installutil /u - with the same caveats I explained above regarding installation options.

I have written more about some subtleties of uninstalling & installing Windows services that you might find interesting and/or helpful - particularly implementing a service (un)installer if you decide to take that route.




回答2:


You must install the service. This can easily be done with the installutil in your .net framework folder like this:

installutil yourproject.exe

If you then want to debug the service just attach it from visual studio via "Debug" - "Attach to process". For more details see: http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx



来源:https://stackoverflow.com/questions/16455236/windows-service-application-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!