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

前端之家收集整理的这篇文章主要介绍了delphi – 在远程计算机上运行应用程序或进程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在远程计算机上运行应用程序或服务.我已经从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",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
原文链接:https://www.f2er.com/delphi/103201.html

猜你在找的Delphi相关文章