在 Windows 网络中启动远程进程

发布于 2024-07-16 10:50:53 字数 523 浏览 12 评论 0原文

我有几台从机和一台主机,它们一起运行分布式应用程序。 每台从属机器上的进程都必须具有 GUI 和网络访问权限(我认为这将被称为交互式进程)。 为了便于使用,如果主机可以启动/停止这些从机上的进程,那就太好了。

我的第一个想法是使用 WMI 和 Win32_Process 类来启动远程进程,但经过进一步调查,发现以这种方式启动的进程是非交互式和隔离的,因此不能有任何 GUI。 注释说可以使用 Win32_ScheduledJob.Create 创建远程交互进程,但它在我想避免的 LocalSystem 帐户下运行(而且我什至无法让它正常运行)。

有什么好的方法可以解决这个问题呢? 也许可以启动一个帮助应用程序,然后启动一个正确的进程,但这看起来很脏。

编辑:当我尝试使用 PsExec 时,它真的很笨重并且慢得要命(不知道为什么)。 进一步查看 PsExec ,它似乎在远程计算机上安装了一个临时服务来启动应用程序。 这是使用正确身份生成交互式进程的唯一方法吗? 我应该在节点设置中包含辅助服务吗? 但即便如此,我该如何与它沟通呢?

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.

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).

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

枫以 2024-07-23 10:50:53

PsExec 是 sysinternals 套件的一部分,可以执行此操作

http://technet.microsoft。 com/en-us/sysinternals/bb897553.aspx

如果您的服务器运行的是 Windows 2008,您还可以使用

终端服务远程应用

PsExec is part of the sysinternals suite that can do that

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

If your servers are running windows 2008 you can also use

Terminal Services Remote App

つ低調成傷 2024-07-23 10:50:53

您可以使用“at”命令。

打开命令行并

at /?

在终端中键入。 一个缺点是远程系统上的时间需要在您的合理的增量范围内。 它也不是即时的。 您必须等待几秒钟才能确保远程调度程序不会完全错过该事件。

有一个与此等效的 WMI,并且具有与以下内容相同的基本警告:

清单 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

我认为大多数其他方法都可以做到这一点(无需安装您自己的服务)由于漏洞而被各种服务包关闭。

You can use the "at" command.

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:

LISTING 3: Code to Create an Interactive Process on Windows Server 2003, Windows XP, and Win2K SP3 Machines

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.

祁梦 2024-07-23 10:50:53

如果整个组都在您的控制之下,则可以将这些远程进程实现为 Windows 服务。 服务可以是交互式的(但默认情况下不是),并且可以通过每台 Windows PC 上运行的标准服务控制管理器进行远程控制。

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.

我不在是我 2024-07-23 10:50:53

请问为什么从属进程需要有GUI? 我有类似的设置,但仅在初始设置期间需要 GUI。

无论如何,这就是我所做的,但不幸的是它依赖于作为 LocalSystem 帐户运行的进程,我知道如果您确实需要 GUI,您会试图避免这种情况。

为了给您提供一些背景知识,我必须分发的应用程序是 Hudson,这是一个早期的应用程序版本中,您分发它的方式是通过运行 Java WebStart 应用程序,因此需要 GUI(至少在设置期间,以帮助故障排除)。

我所做的是使用 sc.exe 将从属应用程序设置为从属计算机上的服务(这是一个正确的 PITA,幸运的是您只执行一次)。 大致如下:

sc.exe create SlaveService binPath= c:\path\to\slave.exe type= interact DisplayName= "The Slave Service"

注意参数后面的空格(binPath= 等),这些是必要的。 另请注意,我发现删除“type=interact”并在服务控制台中手动更改它更容易。

然后在主服务器上,也使用 sc.exe,远程启动该服务:

sc.exe \\slavemachine start SlaveService

并验证该程序是否在从属计算机上运行。

现在就我而言,除了初始故障排除之外,我并不真正需要 GUI。 一旦一切正常运行,我只需将服务配置为作为服务帐户运行,但不再以交互模式运行。

我希望你觉得这有帮助。

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.

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.

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).

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 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.

Then on the master, also using sc.exe, I start the service remotely:

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.

I hope you find this helpful.

愁以何悠 2024-07-23 10:50:53

为了实现这一点,您需要几个组件。

首先,您需要一种与远程计算机通信的方法。

其次,您需要在远程计算机上进行侦听以启动您的应用程序。

最重要的是,其他建议都使用这些组件中的一个或两个组件的内置内容,只要任何给定解决方案的限制是适当的,这就可以。

PsExec 看起来是最有前途的开箱即用解决方案。 否则,您可以推出自己的应用程序来通过 TCP/命名管道/其他方式侦听简单消息,然后生成适当的子进程。 唯一需要注意的是,您需要非常小心安全性,特别是如果任何机器公开暴露的话。

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.

风吹过旳痕迹 2024-07-23 10:50:53

下面两篇文章使用.NET来执行远程进程。

  1. 使用WMI

    http://weblogs.asp.net/steveschofield/archive/2006/06/06/WMI---start-a-process-on-remote-machine-passing-credentials_2E00_.aspx


  2. 代码项目示例

http://www.codeproject.com/KB/IP/RemotingExec.aspx< /a>

示例使用自定义凭据执行 远程可执行文件是一个 Win Form 应用程序。
希望这可以帮助。

The following two post use .NET to execute remote processes.

  1. Using WMI

    http://weblogs.asp.net/steveschofield/archive/2006/06/06/WMI---start-a-process-on-remote-machine-passing-credentials_2E00_.aspx

  2. Codeproject Example

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.

歌枕肩 2024-07-23 10:50:53

PSTools 套件由 Sysinternals 开发,非常出色,以至于该公司在一段时间后被 Microsoft 收购。 使用这些工具是完成任务的最佳方式。

我看到您提到了交互式运行应用程序的问题。 我可以建议使用 /i 开关以交互方式运行应用程序。 PSTools 提供您正在寻找的所有功能。 您只需调整开关即可获得您想要的结果。

我在使用 PSTools 的应用程序中从未遇到过您所描述的缓慢情况。

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.

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've never experienced the slowness you describe in my applications that use PSTools.

最好是你 2024-07-23 10:50:53

MPICH2 经常用于高性能计算集群,应该能够做什么你要。 即使您不使用它在计算机之间传递消息,您也可以使用其进程启动器从主机启动所有进程。 可以将其设置为作为计算机上的特定 Windows 用户进行身份验证。

MPICH2 is 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文