Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows, Start service System.InvalidOperationException: Cannot start service on computer '.' Access in Denied(Running as Admin)

Tags:

I am trying to start service using the below code. This works fine for 99% machines but i get this issue on user machines. Any help to be able to reproduce this error or why this issue happens.

            ServiceController sc = new ServiceController(name);

            if (sc.Status == ServiceControllerStatus.Running ||
                    sc.Status == ServiceControllerStatus.StartPending)
            {
                sc.WaitForStatus(ServiceControllerStatus.Running);
                Logger.Info("Service already running");
                return true;
            }
            sc.Start();

Error I receive is

System.InvalidOperationException: Cannot start service on computer '.'. ---> System.ComponentModel.Win32Exception: Access is denied

I am running with Administrator privileges

When creating the service I also run sc sdset command to make service start stop by non admin processes.

like image 385
Nitin Agarwal Avatar asked May 19 '16 03:05

Nitin Agarwal


People also ask

Can't start service access is denied?

One of the causes for this error is insufficient permissions (Authenticated Users) in your local folder. To give permission for 'Authenticated Users' Open the security tab in properties of your folder, Edit and Add 'Authenticated Users' group and Apply changes.

Can't start a service error 5 access is denied?

This typically occurs due to insufficient permissions on the system. Therefore, many people can fix Error 5: Access is denied error by simply trying to run the command or launch an installer with administrator's rights.


1 Answers

There is a whole thread about it in social msdn. The issue persisted for numerous users and it seems you do not have enough privileges to start the service, in which case you will have to change the service into Administrative account:

make sure that the service is set to Local Account by:

  • Rightclick on the property(in Services.msc panel).
  • select the Log on option

And then check again to see if it's working.

like image 153
Barr J Avatar answered Sep 28 '22 01:09

Barr J