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.
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);