简体   繁体   English

在上下文中启动远程进程

[英]start remote process within the context

I am wondering how to start process remotely within the users context like he started it.我想知道如何在用户上下文中远程启动进程,就像他启动它一样。 Let me explain.让我解释。 I know how to start process remotely, so for example I want to start notepad:我知道如何远程启动进程,所以例如我想启动记事本:

Invoke-WmiMethod win32_process -name create -ComputerName $remoteMachine -ArgumentList "notepad" -credential (Get-Credential)

the problem is that it starts notepad "in the backround" (not in the users context), so in this case he won't see opened "notepad" dialog/process (he will see notepad just in the list of processes in task manager).问题是它“在后台”启动记事本(而不是在用户上下文中),所以在这种情况下,他不会看到打开的“记事本”对话框/进程(他只会在任务管理器的进程列表中看到记事本)。 I want him to see notepad window dialog.我想让他看到记事本 window 对话框。

Does anybody know how to achieve that?有人知道如何实现吗?

Use built-in SchTasks.exe for a supported way to create processes on a remote system.使用内置的 SchTasks.exe 以支持在远程系统上创建进程的方式。 This interfaces with the built-in Task Scheduler service and does not require PsExec.exe.这与内置的任务计划程序服务交互,不需要 PsExec.exe。

To create a task on a remote machine (in this example running as SYSTEM):要在远程机器上创建任务(在此示例中以 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.我们使用 ONSTART 作为计划,但随后我们手动启动进程并在计划被触发之前将其删除。 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.您还可以指定/SC ONCE /SD "01/01/1980" /ST "00:00:00"具有相同的效果。
  • This example is running as System.此示例作为系统运行。 To run as the logged-in user, provided you know who that is use /RU "DOMAIN\USER" .以登录用户身份运行,前提是您知道是谁使用/RU "DOMAIN\USER" This will work without a password ( /RP option) if the user is logged in.如果用户登录,这将在没有密码( /RP选项)的情况下工作。
  • You can use /Query /S COMPUTERNAME /TN "RemoteProcess" /V to find the current status eg to wait for exit and then read the exit code.您可以使用/Query /S COMPUTERNAME /TN "RemoteProcess" /V来查找当前状态,例如等待退出,然后读取退出代码。

You can also do all the above with script using the Task Scheduler Scripting Objects:您还可以使用任务计划程序脚本对象通过脚本执行上述所有操作:

You cannot start interactive processes using WMI or PowerSHell remoting.您无法使用 WMI 或 PowerSHell 远程处理启动交互式进程。 This is a security limitation/feature.这是一个安全限制/功能。 You need to use PSExec if you want to start remote interactive processes.如果要启动远程交互进程,则需要使用 PSExec。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM