start remote process within the context

冷暖自知 提交于 2019-11-27 15:39:33

You cannot start interactive processes using WMI or PowerSHell remoting. This is a security limitation/feature. You need to use PSExec if you want to start remote interactive processes.

Use built-in SchTasks.exe for a supported way to create processes on a remote system. This interfaces with the built-in Task Scheduler service and does not require PsExec.exe.

To create a task on a remote machine (in this example running as SYSTEM):

schtasks.exe /create /F /S COMPUTERNAME /RU "NT AUTHORITY\SYSTEM" /RL HIGHEST /SC ONSTART /TN "RemoteProcess" /TR "program.exe \"argument 1\" \"argument 2\""

schtasks.exe /Run /S COMPUTERNAME /I /TN "RemoteProcess"

schtasks.exe /Delete /S COMPUTERNAME /TN "RemoteProcess"

Notes:

  • We use ONSTART as the schedule, but then we start the process manually and delete it before the schedule is fired. This effectively means "just do it now". You could also specify /SC ONCE /SD "01/01/1980" /ST "00:00:00" which would have the same effect.
  • This example is running as System. To run as the logged-in user, provided you know who that is use /RU "DOMAIN\USER". This will work without a password (/RP option) if the user is logged in .
  • You can use /Query /S COMPUTERNAME /TN "RemoteProcess" /V to find the current status e.g. to wait for exit and then read the exit code.

You can also do all the above with script using the Task Scheduler Scripting Objects:

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