views:

149

answers:

2

Hi,

I'm trying to control Windows Services that are installed in a remote computer. I'm using the ServiceController class.

I have this:

ServiceController svc =  new ServiceController("MyWindowsService", "COMPUTER_NAME");

With this, I can get the status of the Windows Service like this:

string status = svc.Status.ToString();

But I can't control the Windows Service (by doing svc.Start(); or svc.Stop();). I get the following exception:

Cannot open Servicexxx service on computer 'COMPUTER_NAME'

That's normal, I suppose there is something to do with access permissions. But how? I've looked into Google but didn't find what I was looking for. However I often read something related to impersonation, but I don't know what that means.

NB: The local and remote computers are both running Win XP Pro.

Thanks.

A: 

Problem solved.

Impersonation consists in running a piece of code using a certain logon/password. I found this very useful project: http://www.codeproject.com/KB/cs/svcmgr.aspx?display=Print that helped me a lot!

Amokrane
+1  A: 

Starting and stopping services is a highly privileged operation, normally available only to administrators. Ensure that the user account you use has sufficient privileges on the target machine. Ask more questions about it at serverfault.com

Hans Passant
The tool I'm building will be used by the administrators!
Amokrane
The key is that the user on your machine has enough privileges on the *other* machine. Note that impersonation is *not* a good solution, you'll have the password and user name of a privileged account in your source code. That's a nasty security leak.
Hans Passant
The logon/password won't be in the code but in a config file that will be used by the administrators so the security isn't an issue I think :).
Amokrane
Well, make up your mind. If an admin should have access to your machine but not the other then don't give him the password to the other.
Hans Passant
Sure but how the "others" can access to this information, since it's contained in the config file that is not shared?
Amokrane
You *really* need to talk to the person that is responsible for securing these machines. She can explain the security problems to you in your native language.
Hans Passant
I already did. She explained and agreed with me. (FYI: I understand english).
Amokrane
Strange. Well, she's the boss. Over and out.
Hans Passant