Run application or Process on a remote computer

冷暖自知 提交于 2019-11-29 10:15:51

问题


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.


回答1:


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

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).

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



回答2:


ssh is a good choice if you will be streaming anything sensitive. There are even a few FOSS sshd servers for windows that do not rely on cygwin.




回答3:


The other possiblity would be to use the windows AT command which schedules tasks via the windows scheduler. You can submit jobs remotely with the command as long as you have administrator access and the schedule service is running on the other machine. To examine the syntax, just open a CMD window and type AT /?.

for example to run something on machine named "server" at 4am, just enter the command

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


来源:https://stackoverflow.com/questions/677867/run-application-or-process-on-a-remote-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!