Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 在远程计算机上运行应用程序或进程_Delphi_Delphi 2007 - Fatal编程技术网

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

Delphi 在远程计算机上运行应用程序或进程,delphi,delphi-2007,Delphi,Delphi 2007,我需要在远程计算机上运行应用程序或服务。我已经成功地使用了Sysinternal中的psexec,但我正在调查并希望比较其他选择。 最终,该命令将在Delphi应用程序中运行。谢谢你,皮特。如果你想遵循类似PSexec的路线,这里有一个示例(使用C++)源代码 或者您可以下载更新的XCmd项目 本质上,它在运行时提取服务,将其复制到远程系统,将其作为服务安装,然后连接到它(通过命名管道) 另一个选项是使用WMI的内置远程执行功能。下面是一个VBScript示例,您可以将其转换为Delphi。下面

我需要在远程计算机上运行应用程序或服务。我已经成功地使用了Sysinternal中的psexec,但我正在调查并希望比较其他选择。
最终,该命令将在Delphi应用程序中运行。谢谢你,皮特。

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

或者您可以下载更新的XCmd项目

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

另一个选项是使用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
”此脚本提供在远程计算机上执行命令的功能
'这使用WMI并要求您在远程计算机上具有管理权限
'
Dim STRC计算机,strCommandLineToRun
'将句点更改为IP地址或计算机名
strComputer=“.”示例:strComputer=“192.168.1.105”
'这是计算机上文件的路径,其名称/IP地址存储在strComputer变量中
strCommandLineToRun=“c:\windows\system32\calc.exe”
'这将调用函数在远程计算机上运行进程
远程执行strComputer、、、strCommandLineToRun
函数RemoteExecute(strServer、strUser、strPassword、CmdLine)
常量模拟=3
RemoteExecute=-1
Set Locator=CreateObject(“WbemScripting.SWbemLocator”)
Set Service=Locator.ConnectServer(strServer,“root\cimv2”、strUser、strPassword)
Service.Security\uu.ImpersonationLevel=模拟
设置进程=Service.Get(“Win32_进程”)
结果=Process.Create(CmdLine,,ProcessId)
如果(结果0),则
WScript.Echo“创建远程进程失败:”&结果
Wscript.Quit
如果结束
RemoteExecute=ProcessId
端函数

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

例如,要在凌晨4点在名为“server”的机器上运行某个程序,只需输入以下命令

AT \\server 4:00 "c:\something.bat"

如果您要流式传输任何敏感内容,ssh是一个不错的选择。甚至有一些windows的FOSS sshd服务器不依赖cygwin。

看起来有人已经用Delphi完成了这项工作(源代码):