在 Windows 网络中启动远程进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/711604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Starting remote processes in a Windows network
提问by gix
I have several slave machines and a master machine which together run a distributed application. Processes on each slave machine have to have a GUI and network access (I think it would be called an interactive process then). For ease of use it would be nice if the master machine could start/stop the processes on those slave machines.
我有几台从机和一台主机,它们一起运行分布式应用程序。每台从机上的进程都必须具有 GUI 和网络访问权限(我认为那时它会被称为交互式进程)。为了便于使用,如果主机可以启动/停止那些从机上的进程,那就太好了。
My first idea was to use WMI and the Win32_Process class to start a remote process but upon further investigation it was reveiled that processes started this way are non-interactive and isolated, and thus cannot have any GUI. A note says that one can use Win32_ScheduledJob.Create to create a remote interactive process, but it runs under the LocalSystem account which I would like to avoid (also I couldn't even get it to run properly).
我的第一个想法是使用 WMI 和 Win32_Process 类来启动远程进程,但经过进一步调查,发现以这种方式启动的进程是非交互式和隔离的,因此不能有任何 GUI。一个注释说可以使用 Win32_ScheduledJob.Create 创建一个远程交互进程,但它在我想避免的 LocalSystem 帐户下运行(我什至无法让它正常运行)。
What would be good ways to solve this problem? Maybe it is possible to launch a helper application which in turn starts a proper process, but that seems quite dirty.
解决这个问题的好方法是什么?也许可以启动一个辅助应用程序,然后启动一个正确的进程,但这看起来很脏。
Edit: PsExec was really clunky when I tried it and slow as hell (not sure why). Looking further at PsExec it seems it installs a temporary service on the remote machine to launch the application. Would this be the only way to spawn an interactive process using a proper identity? Should I include a helper service in the setup for the nodes? But even then, how would I communicate with it then?
编辑:当我尝试 PsExec 时,它真的很笨重,而且速度很慢(不知道为什么)。进一步查看 PsExec,它似乎在远程机器上安装了一个临时服务来启动应用程序。这是使用正确身份生成交互式过程的唯一方法吗?我应该在节点的设置中包含帮助服务吗?但即便如此,我将如何与它沟通呢?
采纳答案by Ryu
PsExec is part of the sysinternals suite that can do that
PsExec 是可以做到这一点的 sysinternals 套件的一部分
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
If your servers are running windows 2008 you can also use
如果您的服务器运行的是 Windows 2008,您还可以使用
回答by Christopher
You can use the "at" command.
您可以使用“at”命令。
Open a command-line and type
打开命令行并输入
at /?
Into the terminal. The one downside is that the time on the remote system needs to be within some reasonable delta of yours. It's also not instant. You have to wait a few seconds to make sure the remote scheduler doesn't miss the event entirely.
进入终端。一个缺点是远程系统上的时间需要在您的合理增量内。它也不是即时的。您必须等待几秒钟以确保远程调度程序不会完全错过该事件。
There is a WMI equivalent to this, and has the same basic caveats as at:
有一个与此等效的 WMI,并且具有与以下相同的基本警告:
LISTING 3: Code to Create an Interactive Process on Windows Server 2003, Windows XP, and Win2K SP3 Machines
清单 3:在 Windows Server 2003、Windows XP 和 Win2K SP3 机器上创建交互式进程的代码
Const INTERVAL = "n"
Const MINUTES = 1
strComputer = "compaq575"
strCommand = "calc.exe"
Set objWMIService = _
GetObject("winmgmts:\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = _
CreateObject("WbemScripting.SWbemDateTime")
objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, _
MINUTES, Now()))
intReturnValue = objScheduledJob.Create(strCommand, _
objSWbemDateTime.Value, False, 0, 0, True, intJobID)
WScript.Echo "Job ID: " & intJobID
I think most of the other ways to do it (without installing your own service) have been turned off by various service packs because of vulnerabilities.
我认为大多数其他方法(不安装您自己的服务)已被各种服务包由于漏洞而关闭。
回答by Ganesh R.
The following two post use .NET to execute remote processes.
以下两篇文章使用 .NET 来执行远程进程。
Using WMI
Codeproject Example
http://www.codeproject.com/KB/IP/RemotingExec.aspx
http://www.codeproject.com/KB/IP/RemotingExec.aspx
The examples execute with custom credentials & the remote executable is a Win Form app. Hope this helps.
这些示例使用自定义凭据执行,远程可执行文件是 Win Form 应用程序。希望这可以帮助。
回答by MSalters
If the enire group is reasonably under your control, it may be possible to implement these remote processes as Windows Services. A service can be interactive (not by default though) and it can be remotely controlled via the standard Service Control Manager running on each Windows PC.
如果整个组在您的合理控制之下,则可以将这些远程进程实现为 Windows 服务。服务可以是交互式的(虽然不是默认的),并且可以通过在每台 Windows PC 上运行的标准服务控制管理器进行远程控制。
回答by Hyman Leow
May I ask why the slave processes need to have a GUI? I have a similar set up, but needed a GUI only during initial set up.
请问为什么slave进程需要有GUI?我有类似的设置,但仅在初始设置期间需要 GUI。
Anyway, here's what I've done, but unfortunately it relies on the process running as the LocalSystem account, which I understand you're trying to avoid, if you really need the GUI.
无论如何,这就是我所做的,但不幸的是,它依赖于作为 LocalSystem 帐户运行的进程,我知道如果您真的需要 GUI,您正试图避免这种情况。
To give you a little bit of background, the application I had to distribute was Hudson, and this was an earlier version where the way you distribute it is by running a Java WebStart application, and thus the need for a GUI (at least during set up, to help troubleshooting).
为了给您一点背景知识,我必须分发的应用程序是Hudson,这是一个早期版本,您分发它的方式是通过运行 Java WebStart 应用程序,因此需要一个 GUI(至少在设置期间) up,以帮助故障排除)。
What I did was set up the slave applications as services on the slave machines by using sc.exe (which is a PITA to get right, fortunately you only do this once). Something along the lines of:
我所做的是使用 sc.exe 将从属应用程序设置为从属计算机上的服务(这是正确的 PITA,幸运的是您只执行一次)。类似的东西:
sc.exe create SlaveService binPath= c:\path\to\slave.exe type= interact DisplayName= "The Slave Service"
Note the spaces after the parameters (binPath= etc), those are necessary. Note also that I found it easier to drop the "type= interact" and manually change it in the service console.
注意参数后面的空格(binPath= 等),这些是必需的。另请注意,我发现删除“type=interact”并在服务控制台中手动更改它更容易。
Then on the master, also using sc.exe, I start the service remotely:
然后在master上,同样使用sc.exe,我远程启动服务:
sc.exe \slavemachine start SlaveService
And verified that the program was running on the slave machines.
并验证程序在从机上运行。
Now in my case, I did not really need the GUI, other than for initial troubleshooting. As soon as I got everything running properly, I simply configured the service to run as a service account, but no longer in interactive mode.
现在就我而言,除了初始故障排除之外,我并不真正需要 GUI。一旦一切正常运行,我只需将服务配置为作为服务帐户运行,但不再处于交互模式。
I hope you find this helpful.
我希望你觉得这有帮助。
回答by kyoryu
There's a couple of components you're going to need to make this happen.
要实现这一点,您需要几个组件。
First, you'll need a method of communicating with the remote machine.
首先,您需要一种与远程机器进行通信的方法。
Second, you'll need something on the remote machine listening that can start your application.
其次,您需要在远程机器上侦听一些可以启动您的应用程序的东西。
The other suggestions above all use something built-in for one or both of these components, which is fine, so long as the restrictions of any of the given solutions are appropriate.
上面的其他建议都为这些组件中的一个或两个使用内置的东西,这很好,只要任何给定解决方案的限制是合适的。
PsExec looks like the most promising, out-of-the-box solution. Otherwise, you can roll your own app to listen to simple messages via TCP/named pipes/whatever and just spawn appropriate sub-processes. The only caveat with that is you'll want to be pretty careful around security, especially if any of the machines are publicly exposed.
PsExec 看起来是最有前途的、开箱即用的解决方案。否则,您可以推出自己的应用程序以通过 TCP/命名管道/任何方式侦听简单消息,然后生成适当的子进程。唯一需要注意的是,您需要在安全方面非常小心,特别是如果任何机器都公开暴露。
回答by Jim Hunziker
MPICH2is often used in High Performance Computing clusters and should be able to do what you want. Even if you don't use it for passing the messages between machines, you can use its process launcher to start all of the processes up from the master machine. It can be set up to authenticate as a particular Windows user on the machines.
MPICH2常用于高性能计算集群,应该能够做你想做的事。即使您不使用它在机器之间传递消息,您也可以使用其进程启动器从主机启动所有进程。它可以设置为作为机器上的特定 Windows 用户进行身份验证。
回答by slypete
The PSTools suite was developed by Sysinternals and was so great that the company was purchased by Microsoft some time later. Using these tools is the best way to accomplish your task.
PSTools 套件是由 Sysinternals 开发的,非常棒,以至于该公司在一段时间后被微软收购。使用这些工具是完成任务的最佳方式。
I see you mentioned a problem with running applications interactively. May I suggest using the /i switch to run the application interactively. PSTools offers all of the functionality you are looking for. You just need to play around with the switches to obtain your desired result.
我看到您提到了交互式运行应用程序的问题。我可以建议使用 /i 开关以交互方式运行应用程序。PSTools 提供您正在寻找的所有功能。您只需要玩转开关即可获得所需的结果。
I've never experienced the slowness you describe in my applications that use PSTools.
我从未体验过您在使用 PSTools 的应用程序中描述的缓慢。