ServiceController.start() and ServiceController.stop() are throwing exceptions?

前端 未结 5 1539
野趣味
野趣味 2021-01-21 07:43

The following code is throwing Exception. I don\'t get what mistake I am making in the code. Can somebody help me figure out please. I think it is of some security rights issue.

5条回答
  •  北海茫月
    2021-01-21 08:39

    I found a solution to this problem by providing the machine name of the machine which is currently executing the service in the ServiceController overloaded constructor that takes 2(two) arguments i.e. public ServiceController(/my service's name string/, System.Environment.MachineName/this machine which is executing the service/)

    The version of .Net this solution was tested on was 4.5, hope this helps anyone still looking for a solution.

    Here is what you need to do in code:

    ServiceController serviceController = new ServiceController("myServiceName", System.Environment.MachineName);
    

提交回复
热议问题