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


Look for your permissions. Let me run the application (or Visual Studio) from an administrator account.



+5


source


Your error Access is denied

indicates to me that the identity under which your process / application is running does not have permission to start and stop services.



+2


source


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


You might want to check this question for some help on permissions when starting the service.

0


source







All Articles