在远程计算机上运行应用程序或进程

4

我需要在远程计算机上运行一个应用程序或服务。我已经成功地使用过SysInternals的psexec,但我正在调查并希望了解更多替代方案。 最终这个命令将从Delphi应用程序中运行。谢谢,Pieter。

3个回答

3
如果你想按照PSexec的方式进行操作,这里提供了一个示例(使用C++编写),名为XCmd,点击这里查看源代码。
或者你也可以从SourceForge上下载更新后的XCmd项目(现在称为"The Grim Linker")
基本上,它会在运行时提取服务,将其复制到远程系统中,安装为服务,然后通过命名管道连接到它。
另一个选项是使用WMI内置的远程执行功能。下面是一个VBScript示例,你可以将其转换为Delphi。以下示例在远程系统上执行记事本。
' This script provides a function for executing a command on a remote computer
' This uses WMI and requires that you have administrative righs on the remote machine
'

Dim strComputer, strCommandLineToRun

'change the period to an IP Address or computer name
strComputer = "."   'example: strComputer = "192.168.1.105"

'this is the path to the file on the computer whose name/IP address is stored in the strComputer variable
strCommandLineToRun = "c:\windows\system32\calc.exe"


' This calls the function to run the process on a remote computer
RemoteExecute strComputer,"","",strCommandLineToRun


Function RemoteExecute(strServer, strUser, strPassword, CmdLine)
    Const Impersonate = 3

    RemoteExecute = -1

    Set Locator = CreateObject("WbemScripting.SWbemLocator")
    Set Service = Locator.ConnectServer(strServer, "root\cimv2", strUser, strPassword)

    Service.Security_.ImpersonationLevel = Impersonate 
    Set Process = Service.Get("Win32_Process")

    result = Process.Create(CmdLine, , , ProcessId)

    If (result <> 0) Then
        WScript.Echo "Creating Remote Process Failed: " & result
        Wscript.Quit
    End If

    RemoteExecute = ProcessId
End Function

看起来有人用Delphi(带源代码)完成了这个:http://www.ciuly.com/index.php/delphi/article/1-delphi/42-execute-an-application-on-a-remote-pc.html - Mick

2

如果您需要传输任何敏感信息,ssh是一个不错的选择。甚至有一些适用于Windows的自由软件SSH服务器,它们不依赖于Cygwin。


0
另一种可能性是使用Windows AT命令,通过Windows计划程序安排任务。只要您具有管理员访问权限并且其他计算机上的计划服务正在运行,就可以使用该命令远程提交作业。要查看语法,请打开CMD窗口并键入AT /?
例如,要在名为“server”的计算机上在凌晨4点运行某些内容,只需输入以下命令:
AT \\server 4:00 "c:\something.bat"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接