0

I have a Windows Service and i want to start it using ServiceController.The service runs as LocalSystem.When i am trying to Start it i get:

System.InvalidOperationException: 'Cannot open [service] service on computer '.'.'
Inner Exception Win32Exception:Access is denied

Main

   static void Main(string[] args) {
            using (ServiceController controller = new ServiceController("someService")) {
                controller.Start();
            }
        }

Can i somehow elevate the rights programatically in order to start the service (even if i need to use P/Invoke for Winapi ? ) .

Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152

1 Answers1

1

You do indeed need to elevate. That requires creating a new process to start the service, either explicitly with the runas shell verb, or using the COM elevation moniker.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490