1

I have a problem to start a Service by C#. I get this error message:

System.ComponentModel.Win32Exception (0x80004005): Access denied.

How can I have the permission?

My easy code it's:

ServiceController s = new ServiceController("Service1", Environment.MachineName);
try
{
    s.Start();
}
catch (Exception e)
{
    Console.WriteLine(e.InnerException);
}
help-info.de
  • 6,695
  • 16
  • 39
  • 41
Riccardo
  • 9
  • 3

1 Answers1

1

Like @LasseVågsætherKarlsen said: your application should have sufficient rights and should run elevated. More information here: https://stackoverflow.com/a/2818776/4367

TL;DR;

Add the following to your application manifest:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Rick
  • 3,361
  • 1
  • 22
  • 29