ServiceController service = new ServiceController("MyServiceName");
if ((service.Status.Equals(ServiceControllerStatus.Stopped)) ||
    (service.Status.Equals(ServiceControllerStatus.StopPending)))
    service.Start();
else    service.Stop(); 
its working on xp 32 bit but not working on win 7.ti throws a exception access denied. is t开发者_StackOverflowhere any solution to this.plz help me.
Your C# program has to run with the same credentials as the service you are trying to start, otherwise you will need elevation due to UAC under Windows 7 - there is a sample for that here.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论