如何使用ServiceController远程控制Windows服务?
我正在尝试控制安装在远程计算机上的 Windows 服务。我正在使用 ServiceController
类。
我有这个:
ServiceController svc = new ServiceController("MyWindowsService", "COMPUTER_NAME");
有了这个,我可以像这样获取 Windows 服务的状态:
string status = svc.Status.ToString();
但我无法控制 Windows 服务(通过执行 svc.Start();
或 svc.停止();
)。 我得到以下异常:
无法打开 Servicexxx 服务 计算机“COMPUTER_NAME”
这很正常,我想这与访问权限有关。但如何呢? 我查过谷歌,但没有找到我要找的东西。不过我经常读到一些与冒充相关的内容,但我不知道这意味着什么。
注意:本地和远程计算机都运行 Win XP Pro。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题解决了。
模拟包括使用特定的登录名/密码运行一段代码。我发现这个非常有用的项目: http://www.codeproject.com/ KB/cs/svcmgr.aspx?display=Print 对我帮助很大!
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!
启动和停止服务是一项高度特权的操作,通常只有管理员才能使用。确保您使用的用户帐户在目标计算机上具有足够的权限。在 serverfault.com 上询问更多相关问题
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
为了解决这个问题,请为您的名字提供远程计算机/服务器上的管理员权限(例如域/用户名),您将能够成功运行该包,因为我遇到了同样的问题,并且当我向我的自助服务授予权限时可以在远程访问服务器
In order to solve the issue , give your name the admin permissions on remote computer/server like domain/username and you will able to run the package successfully since i had the same issue and when i gave permissions to my self services were accessible on remote server
我有同样的问题
但已经完成了。
尝试下面的代码
i had same issue
but is done.
try this code bellow