Self install Windows Service in .NET

后端 未结 3 1785
眼角桃花
眼角桃花 2020-12-12 17:40

I have read this question. I have same issue, but I don\'t understand the answer from lubos hasko. How exactly can I do it? Can you someone post me full walkthrough?

3条回答
  •  执笔经年
    2020-12-12 17:45

    First of all, in your Service1 constructor set ServiceName property.

    Excerpt from MSDN:

    The minimum you need to implement in the constructor for a class inherited from ServiceBase is to set the ServiceName on your component. No other processing is specifically required in the constructor. You should handle most initialization in OnStart rather than in the constructor.

    Second of all you need to pass arguments to your service when running it from command line. --install for install, --uninstall for uninstall - look at your switch statement it's doing it on input arguments.

提交回复
热议问题