How do I configure the name of a Windows service upon installation (or easily at compile time)?

前端 未结 3 1937
半阙折子戏
半阙折子戏 2020-12-13 07:06

I\'ve created a Windows service in C#, installed it on a server and it is running fine.

Now I want to install the same service again, but running from a different wo

3条回答
  •  一向
    一向 (楼主)
    2020-12-13 07:50

    You can't pass this in as a command line arg, since InstallUtil doesn't provide the right hooks for that.

    However, you can make your service installer read the ServiceName from a config file. If you look at some code for a typical ServiceInstaller, you'll see it's just a matter of having the appropriate DisplayName and ServiceName properties setup at runtime. These could easily be read from a configuration file instead of being hard-coded.

提交回复
热议问题