c#中的Windows服务应用程序 [英] Windows Service application in c#

查看:37
本文介绍了c#中的Windows服务应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 c# 创建了一个 Windows 服务应用程序.我已按照 this 中的步骤操作msdn 文档,但该服务未列在 Computer -> 的 services 部分中管理 ->服务窗格.

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.

我错过了什么吗?它的 Windows 7.

Am I missing something? its Windows 7.

想运行我的服务来检查功能.

Want to run my service to check the functionality.

谢谢

推荐答案

您需要安装您的服务,以便 Windows 服务控制管理器 (SCM) 了解它(通过生成的注册表项).

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"

对于sc create,任何命令提示符都可以.对于 installutil,Visual Studio 命令提示符是运行它的最简单方法——因为 VS 命令提示符的 PATH 环境变量使得使用 .NET 命令行工具变得容易;根据我的经验,您的服务需要实施服务(卸载)安装程序.

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.

在您安装并实际检查您的服务后,您几乎肯定会在某个时候想要卸载它 - 例如然后在非开发位置安装它的最终版本,或者只是清理散落在已安装服务列表中的开发服务条目.您在 sc deleteinstallutil/u 中有相应的选项 - 与我上面解释的有关安装选项的注意事项相同.

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.

我写了更多关于卸载和卸载的一些细节.安装您可能感兴趣和/或有帮助的 Windows 服务 - 特别是如果您决定采取该路线,则实施服务(卸载)安装程序.

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.

这篇关于c#中的Windows服务应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆