Reputation: 9
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);
}
Upvotes: 1
Views: 240
Reputation: 3451
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" />
Upvotes: 1