Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Service with C #

Tags:

c#

service

I'm trying to start a service with C # but throws 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 is denied at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) at System.ServiceProcess.ServiceController.Stop()

like image 459
gemr1423 Avatar asked Dec 04 '25 19:12

gemr1423


2 Answers

Look for your permissions. May me you need to run your app (or Visual Studio) from Administrator account.

like image 137
Sergey Shulik Avatar answered Dec 06 '25 08:12

Sergey Shulik


Your Access is denied error indicates to me that the identity under which your process / application is running does not have permission to start & stop services.

like image 40
Yuck Avatar answered Dec 06 '25 09:12

Yuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!