在远程计算机上运行应用程序或进程 [英] Run application or Process on a remote computer

查看:296
本文介绍了在远程计算机上运行应用程序或进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在远程计算机上运行应用程序或服务。我已经从SysInternals的psexec取得了成功,但我正在调查中,并希望对其进行补充。
最终该命令将从Delphi应用程序中运行。谢谢,Pieter。

I need to run an application or service on a remote computer. I have had success with psexec from SysInternals, but I am investigating and would like to compre alternatives. Ultimately the command will be run from within a Delphi application. Thanks, Pieter.

推荐答案

如果你想遵循类似PSexec的路由,这里是一个例子(用C ++) 称为XCmd

If you want to follow the PSexec-like route, here is an example (with C++) source, called XCmd.

或者您可以下载更新的XCmd项目(现称为严格链接器)从SourceForge。

Or you can download the updated XCmd project (now called 'The Grim Linker') from SourceForge.

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

Essentially, it extracts a service at run-time, copies it to the remote system, installs it as a service, then connects to it (via named Pipes).

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

The other option is to use WMI's built-in remote execution abilities. Here is an example in VBScript that you could convert to Delphi. The example below executes notepad on the remote system.

' 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

这篇关于在远程计算机上运行应用程序或进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆