Client App Fails to stop Service

R

RML

Hi,

I have created a .Net 2.0 Windows Service which I would like to have
stopped/Started by a .Net 2.0 client windows app.

When logged in as Admin, the client app can start/stop the service fine. If
I am logged in as a user other than Admin, the client fails to stop/start the
service. The error is as follows:

"Cannot open Foo Service on Computer."

I would guess that this is a permission problem, so I looked into the
ServiceControllerPermissions clas, but the documentation is not clear on how
to impliment it.

Is this the right class to use, and if so how do I use it?

RM
 
J

Jeroen Mostert

RML said:
I have created a .Net 2.0 Windows Service which I would like to have
stopped/Started by a .Net 2.0 client windows app.

When logged in as Admin, the client app can start/stop the service fine. If
I am logged in as a user other than Admin, the client fails to stop/start the
service. The error is as follows:

"Cannot open Foo Service on Computer."

I would guess that this is a permission problem,

This is correct. Like most other objects, every service has a DACL
associated with it. By default, service DACLs only allow administrators,
power users and LocalSystem permission to start and stop the service. This
is usually what you want, since services often run in a highly privileged
context.
so I looked into the ServiceControllerPermissions clas, but the
documentation is not clear on how to impliment it.

Is this the right class to use, and if so how do I use it?
No, it's not. ServiceControllerPermission is for code access security only,
and offers an extra layer of security for managed code. That's not what's
stopping you -- the unmanaged permissions on the service are.

Here's a KB article on service DACLs and the risks associated with changing
them: http://support.microsoft.com/kb/914392

Here's a freeware tool to change them which is slightly more intuitive than
"sc" (I didn't test it): http://www.losoft.de/ls_scacl.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top