Start a windows service without elevation

Be.St. picture Be.St. · Mar 19, 2013 · Viewed 13.3k times · Source

I have a windows service "Service1" configured to log on as "Local Service".

I built a console application to start it programmatically.

        var service = new ServiceController("Service1");
        service.Start();

I know that if I run the ConsoleApplication1 from an administrator command prompt it starts smoothly.

And if I run it without elevation I get an:

System error 5 has occurred.

Access is denied.

But, I need to start it without elevation.

Is it possible, or I have to change the way to achieve this?

Answer

Bill_Stewart picture Bill_Stewart · Mar 19, 2013

You can set the ACL for the service itself to allow this. The SetACL.exe utility makes this (somewhat) straightforward; e.g.:

SetACL.exe -on "MyService" -ot srv -actn ace -ace "n:S-1-5-32-545;p:start_stop"

This allows members of the Users group (S-1-5-32-545) to start and stop MyService.