简体   繁体   English

如何更改Windows服务的名称?

[英]How can I change the name of a windows service?

I have a windows service application developed in C#. 我有一个用C#开发的Windows服务应用程序。 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. 我可以创建解决方案的多个副本,但是不确定如何更改服务名称。

Thanks 谢谢

In your win service class that derives from ServiceBase , there is a property that is inherited that you can set called ServiceName . 在从ServiceBase派生的Win服务类中,有一个继承的属性,可以设置为ServiceName You could make an app.config, add a setting for the service name and have your win service class assign that property accordingly. 您可以创建一个app.config,为服务名称添加一个设置,并让您的win服务类相应地分配该属性。 That way each service name will be unique as long as you change the setting in the app.config. 这样,只要您更改app.config中的设置,每个服务名称将是唯一的。

Service name can also be edited via ProjectInstaller design mode. 服务名称也可以通过ProjectInstaller设计模式进行编辑。 There is a property called ServiceName in the ServiceInstaller . ServiceInstaller中有一个称为ServiceName的属性。

The configuration for Windows services are stored in the Registy, under HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services... You will probably want to change both the name of the key (the "folder", and the real name of the service here) and the value "Display Name". Windows服务的配置存储在注册表中的HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services下。您可能希望同时更改密钥的名称(“文件夹”和服务的真实名称),然后值“显示名称”。

It might be better to use a tool like SC.EXE to configure services , to avoid causing problems with bad Registry edits. 最好使用SC.EXE之类的工具来配置服务 ,以避免引起注册表编辑错误的问题。 Although SC can't rename a service in place, it does allow you to delete and create services (just be sure to get all the settings right!). 尽管SC无法在适当的位置重命名服务,但它确实允许您删除和创建服务(只需确保正确设置所有设置!)。

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

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