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

标签 delphi delphi-2007

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

最佳答案

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

或者您可以下载更新的 XCmd 项目 (now called 'The Grim Linker') from SourceForge.

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

另一个选项是使用 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 - 在远程计算机上运行应用程序或进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/677867/

相关文章:

Delphi,使用 WinInet 发布并跟踪上传进度

delphi - 初始化一个常量,它是固定数组的动态数组?

delphi - bpl delphi专家和dll delphi专家有哪些区别

mysql - 使用@variables := in delphi query does not work

delphi - 将 SysUtils.WrapText() 与包含单引号的字符串一起使用

delphi - 帮助解决奇怪的 Delphi 5 IDE 问题

delphi - Chromium 嵌入式框架 : Creating an object fails when using "ExecuteFunctionWithContext"

delphi - Delphi中框架之间的通信

delphi - 使用delphi从.log文件读取时获取 "ÿþI"作为输出数据

delphi - Delphi(XE2)的Unicode版本