Can't start a service by C#

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);
}
c#
windows-services
servicecontroller
asked on Stack Overflow Sep 20, 2019 by desaparecido • edited Sep 20, 2019 by help-info.de

1 Answer

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" />
answered on Stack Overflow Sep 20, 2019 by Rick

User contributions licensed under CC BY-SA 3.0