何使用ServiceController远程控制Windows服

何使用ServiceController远程控制Windows服

本文介绍了如何使用ServiceController远程控制Windows服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试控制安装在远程计算机上的Windows服务.我正在使用 ServiceController 类.

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

我有这个:

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

有了这个,我可以像这样获得Windows服务的状态:

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

string status = svc.Status.ToString();

但是我无法控制Windows服务(通过执行 svc.Start(); svc.Stop(); )).我收到以下异常:

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

那很正常,我想这与访问权限有关.但是如何?我已经调查了Google,但没有找到想要的东西.但是,我经常阅读一些与假冒有关的内容,但我不知道那是什么意思.

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:本地和远程计算机都运行Win XP Pro.

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

推荐答案

问题已解决.

冒名顶替是使用特定的登录名/密码来运行一段代码.我发现这个非常有用的项目: http://www.codeproject.com/KB/cs/svcmgr.aspx?display = Print 对我有很大帮助!

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!

这篇关于如何使用ServiceController远程控制Windows服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 21:51