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