【问题标题】:Run application or Process on a remote computer在远程计算机上运行应用程序或进程
【发布时间】:2009-03-24 15:19:04
【问题描述】:

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

【问题讨论】:

    标签: delphi delphi-2007


    【解决方案1】:

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

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

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

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

    ' 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
    

    【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      例如要在凌晨 4 点在名为“server”的机器上运行一些东西,只需输入命令

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-04
        • 1970-01-01
        • 2010-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-18
        • 2013-11-12
        相关资源
        最近更新 更多