我需要在远程计算机上运行应用程序或服务。我从SysInternals获得了psexec的成功,但我正在调查并希望得到替代方案。 最终,命令将在Delphi应用程序中运行。谢谢,彼得。
答案 0 :(得分:3)
如果你想遵循PSexec类似的路线,这里有一个例子(带有C ++)源called XCmd。
或者您可以下载更新的XCmd项目(now called 'The Grim Linker') from SourceForge.
本质上,它在运行时提取服务,将其复制到远程系统,将其作为服务安装,然后连接到它(通过命名管道)。
另一种选择是使用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
答案 1 :(得分:2)
答案 2 :(得分:0)
另一种可能性是使用Windows AT命令,该命令通过Windows调度程序调度任务。只要您具有管理员访问权限并且计划服务正在另一台计算机上运行,您就可以使用该命令远程提交作业。要检查语法,只需打开CMD窗口并键入 AT /?。
例如,在凌晨4点在名为“server”的机器上运行某些东西,只需输入命令
即可AT \\server 4:00 "c:\something.bat"