简体   繁体   English

如何从其他机器启动Windows服务?

[英]How to start a windows service from other machines?

I have some windows services writtin with C# language that is running on my machine. 我的计算机上正在运行一些使用C#语言编写的Windows服务。 I also created a WPF Application to my customer start and stop theses services. 我还为客户启动和停止这些服务创建了WPF应用程序。 When I run it on the same machine, it works fine, but when I try to run on other machines it does not work, and I got an exception with the message: Cannot open Service Control Manager on compupter 'NAME-PC'. 当我在同一台计算机上运行它时,它可以正常工作,但是当我尝试在其他计算机上运行时,它却不起作用,并且出现了以下消息异常: 无法在计算机“ NAME-PC”上打开服务控制管理器。 This operation might require other privileges. 此操作可能需要其他特权。

My Windows Service has a Project Installer that has a ProcessInstaller with the Account property setted to LocalSystem . 我的Windows服务具有一个项目安装程序,该项目安装程序的ProcessInstaller的Account属性设置为LocalSystem I'm not sure if that influence. 我不确定是否会产生影响。

How could I set the right privileges to other machines can start this service on a specific machine? 我如何设置其他计算机可以在特定计算机上启动此服务的权限?

Thank you. 谢谢。

To assist you in some troubleshooting, as I don't think I can come up with an answer directly given your current info, first, try to change your machine name to an IP address. 为了帮助您进行一些故障排除,因为我认为无法直接根据您的当前信息给出答案,因此,首先,尝试将计算机名称更改为IP地址。 For example, if your WCF service is recieving the command and is trying to restart another service on that computer, then try: 例如,如果您的WCF服务正在接收命令并试图重新启动该计算机上的另一服务,请尝试:

string machine = "127.0.0.1";

The answer to why this would work, is I don't know. 我不知道为什么这行得通的答案。 That may have something to do with the service running as a local user and has no access to your DNS to resolve a hostname. 这可能与以本地用户身份运行的服务有关,并且无法访问DNS来解析主机名。

If this does not work (or even it if does), I would attempt to set up your services using Domain accounts that are dedicated to running the service, and have been given permissions to do what you want them to. 如果这行不通(或者甚至行不通),我将尝试使用专用于运行服务的帐户来设置您的服务,并已被授予执行您希望它们执行操作的权限。 Generally, this is the best practice way of creating services that do anything, since we are not all security experts and our services might be compromised (which might be horrible when running as local system). 通常,这是创建可以执行任何操作的服务的最佳实践方法,因为我们并不是所有人都可以安全工作,并且我们的服务可能会受到损害(当作为本地系统运行时,这可能会很可怕)。

Also, if your service is trying to start a service on a remote machine (not local) then you will need to have some sort of network account that has permissions to do so. 另外,如果您的服务试图在远程计算机(不是本地计算机)上启动服务,那么您将需要具有某种权限的网络帐户。

I think it is a security thing. 我认为这是安全的事情。
You need to grant rights to start that service 您需要授予权限才能启动该服务

How to grant users rights to manage services in Windows Server 2003 如何授予用户在Windows Server 2003中管理服务的权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM