How to pass a parameter to a windows service once and for all at install instead of each start

前端 未结 8 2063
南旧
南旧 2020-12-09 04:13

We have a Windows Service application that can accept command line parameters like:

MyService -option 

So far, when we want to start the

相关标签:
8条回答
  • 2020-12-09 04:44

    The only thing that worked for me was to add the parameter to the ImagePath on the registry like the following image :

    0 讨论(0)
  • 2020-12-09 04:45

    According to the ServiceBase.OnStart documentation:

    The arguments entered in the console are not saved; they are passed to the service on a one-time basis when the service is started from the control panel. Arguments that must be present when the service is automatically started can be placed in the ImagePath string value for the service's registry key (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\). You can obtain the arguments from the registry using the GetCommandLineArgs method, for example: string[] imagePathArgs = Environment.GetCommandLineArgs();.

    0 讨论(0)
提交回复
热议问题