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 ()
Look for your permissions. Let me run the application (or Visual Studio) from an administrator account.
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.
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
You might want to check this question for some help on permissions when starting the service.