3

I have a Windows service that runs on my local PC. My operating system is windows 7. I want to Start my service via C# code without going through "Computer Management > Services".

When I run the code below it gives me the following Exception:

"Service {ServiceName} was not found on computer '.'."

ServiceController service = new ServiceController(serviceName);
try
{
    TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

    service.Start();
    service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
    // ...
}

I've been through many posts regarding this scenario and all mention that this is a security feature of Windows 7. Is there a way to run this service without middling the Admin Groups?

Athafoud
  • 2,640
  • 2
  • 39
  • 52
Thilo
  • 89
  • 2
  • 7

2 Answers2

0

You're probably running into a UAC problem. You need to add a manifest file to your app the indicates the app must be run as an administrator. This will cause Windows to prompt for elevation when your program runs. Here's an article that walks you through the issue/solution:

http://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware

And a related stackoverflow post:

How do I force my .NET application to run as administrator?

Community
  • 1
  • 1
Matt Varblow
  • 7,041
  • 3
  • 32
  • 42
0

It can be about ur framework couldnt selected. U can select it then refresh ur IIS. enter image description here

Ilaria
  • 147
  • 2
  • 11