How can I restart a windows service programmatically in .NET

后端 未结 10 1225
青春惊慌失措
青春惊慌失措 2020-12-02 18:21

How can I restart a windows service programmatically in .NET?
Also, I need to do an operation when the service restart is completed.

10条回答
  •  攒了一身酷
    2020-12-02 18:50

    How about

    var theController = new System.ServiceProcess.ServiceController("IISAdmin");
    
    theController.Stop();
    theController.Start();
    

    Don't forget to add the System.ServiceProcess.dll to your project for this to work.

提交回复
热议问题