How to specify command line options for service in TopShelf

前端 未结 3 1443
予麋鹿
予麋鹿 2021-01-11 22:59

I am using command line arguments to pass some configuration to the windows service (it will be few instances with different command lines).

My code looks like this:

3条回答
  •  生来不讨喜
    2021-01-11 23:19

    You can't modify the command line passed to the service. I get around this by saving those parameters to configuration next to the exe. So a user can do this:

    service.exe run /sqlserver:connectionstring
    

    and the app saves the connectionstring to a file (either using System.IO.File or using ConfigurationManager)

    Then, if the user does this:

    service.exe run
    

    Or if the service runs as a windows service, then the app just loads from config.

提交回复
热议问题