Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
402 views
Welcome To Ask or Share your Answers For Others

1 Answer

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...