4

我需要在远程计算机上运行应用程序或服务。我在 SysInternals 的 psexec 上取得了成功,但我正在调查并想比较替代方案。最终,该命令将从 Delphi 应用程序中运行。谢谢,彼得。

4

3 回答 3

3

如果您想遵循类似 PSexec 的路线,这里有一个示例(使用 C++)源,名为 XCmd

或者,您可以从 SourceForge 下载更新的 XCmd 项目(现在称为“The Grim Linker”)。

本质上,它在运行时提取服务,将其复制到远程系统,将其安装为服务,然后连接到它(通过命名管道)。

另一种选择是使用 WMI 的内置远程执行功能。这是一个可以转换为 Delphi 的 VBScript 示例。下面的示例在远程系统上执行记事本。

' 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
于 2009-03-24T16:20:41.990 回答
2

如果您要传输任何敏感内容,ssh 是一个不错的选择。甚至还有一些不依赖 cygwin 的 Windows 自由开源 sshd 服务器。

于 2009-03-25T17:22:44.267 回答
0

另一种可能性是使用 windows AT 命令,该命令通过 windows 调度程序安排任务。只要您具有管理员访问权限并且计划服务正在另一台计算机上运行,​​您就可以使用该命令远程提交作业。要检查语法,只需打开 CMD 窗口并输入AT /? .

例如,要在凌晨 4 点在名为“server”的机器上运行某些东西,只需输入命令

AT \\server 4:00 "c:\something.bat"
于 2009-03-25T17:19:35.850 回答