开发者

How can I change the name of a windows service?

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 c开发者_开发问答hange 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. 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.


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".

It might be better to use a tool like SC.EXE to configure services, to avoid causing problems with bad Registry edits. 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!).


Service name can also be edited via ProjectInstaller design mode. There is a property called ServiceName in the ServiceInstaller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜