Get Started With C #
I'm trying to start a service from C # but it gives me the following error:
ServiceController service = new ServiceController(sServiceName);
service.MachineName = localComputerName;
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
System.InvalidOperationException: Cannot open service on computer System.ComponentModel.Win32Exception: Access denied when System.ServiceProcess.ServiceController.GetServiceHandle (Int32 wishAccess) at System.ServiceProcess.ServiceController.Stop ()
0
source to share
4 answers
Do you have red exception text? you just don't have permission to start the server. Read: http://msdn.microsoft.com/en-us/library/h846e9b3.aspx ( http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontrollerpermission.aspx ) or just run the app as administrator
+1
source to share
You might want to check this question for some help on permissions when starting the service.
0
source to share