如何更改 Windows 服务的名称? [英] How can I change the name of a windows service?

查看:63
本文介绍了如何更改 Windows 服务的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C# 开发的 Windows 服务应用程序.需要使用不同的配置文件运行相同的服务.要在同一台机器上运行这些,我需要更改服务的名称.我可以创建解决方案的多个副本,但不确定如何更改服务名称.

I have a windows service application developed in C#. The same service needs to be run with different config files. To run on these on the same machine I would need to change the name of the service. I can create multiple copies of the solution, but not sure how to change the names of the services.

谢谢

推荐答案

在从 ServiceBase 派生的 win 服务类中,有一个可以设置的继承属性,名为 ServiceName.您可以创建一个 app.config,为服务名称添加设置,并让您的 win 服务类相应地分配该属性.这样,只要您更改 app.config 中的设置,每个服务名称就会是唯一的.

In your win service class that derives from ServiceBase, there is a property that is inherited that you can set called ServiceName. You could make an app.config, add a setting for the service name and have your win service class assign that property accordingly. That way each service name will be unique as long as you change the setting in the app.config.

这篇关于如何更改 Windows 服务的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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