简体   繁体   English

c#中的Windows服务应用程序

[英]Windows Service application in c#

I have created a Windows Service application using c# . Windows Service application using c#创建了一个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 . 我已按照 msdn文档中的步骤操作,但该服务未列在Computer -> Manage -> Service pane的服务部分中。

Am I missing something? 我错过了什么吗? its Windows 7 . 它的Windows 7

Want to run my service to check the functionality. 想要运行我的服务来检查功能。

Thanks 谢谢

You must install the service. 您必须安装该服务。 This can easily be done with the installutil in your .net framework folder like this: 这可以通过.net框架文件夹中的installutil轻松完成,如下所示:

installutil yourproject.exe

If you then want to debug the service just attach it from visual studio via "Debug" - "Attach to process". 如果您想调试服务,只需通过“Debug” - “Attach to process”从visual studio中附加它。 For more details see: http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx 有关更多详细信息,请参阅: http//msdn.microsoft.com/en-us/library/sd8zc8ha.aspx

You need to install your service for the Windows Service Control Manager (SCM) to know about it (by virtue of a resulting registry entry). 您需要为Windows服务控制管理器(SCM)安装服务以了解它(凭借生成的注册表项)。

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. 对于sc create ,任何命令提示都应该这样做。 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; 对于installutil ,Visual Studio命令提示符是运行它的最简单方法 - 因为VS命令提示符的PATH环境变量使得使用.NET命令行工具变得容易; and your service needs to implement a service (un)installer in my experience. 根据我的经验,您的服务需要实现服务(un)安装程序。

After you install and reality check your service, you will almost certainly want to uninstall it at some point - eg 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. 您在sc deleteinstallutil /u有相应的选项 - 我在上面解释了有关安装选项的相同注意事项。

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. 我已经写了更多关于卸载和安装您可能感兴趣和/或有用的Windows服务的一些细微之处 - 特别是在您决定采用该路由时实现服务(un)安装程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM