加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 10:12:50 所属栏目:大数据 来源:网络整理
导读:我需要在远程计算机上运行应用程序或服务.我已经从SysInternals获得了psexec的成功,但我正在调查并希望得到替代方案. 最终,命令将在Delphi应用程序中运行.谢谢,彼得. 解决方法 如果你想遵循类似PSexec的路线,这里有一个例子(带有C)源,called XCmd. 或者您可
我需要在远程计算机上运行应用程序或服务.我已经从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:windowssystem32calc.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,"rootcimv2",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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读