如何以交互方式为所有登录用户运行psexec工具?

时间:2018-03-02 14:46:34

标签: windows psexec

我知道如何使用psexec以交互方式为单个会话运行程序:

PsExec.exe -s -i 7 \\computername notepad.exe

但我需要为所有登录用户运行它,而不仅仅是针对特定会话。

怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用Qwinsta命令列出所有活动会话(更多信息here):

qwinsta /SERVER:servername

以下是此命令的示例输出:

enter image description here

现在,您可以从列ID获取所有RDP连接ID并运行命令:

PsExec.exe -s -i 0  \computername notepad.exe
PsExec.exe -s -i 1  \computername notepad.exe
PsExec.exe -s -i 17 \computername notepad.exe
PsExec.exe -s -i 19 \computername notepad.exe
PsExec.exe -s -i 32 \computername notepad.exe
PsExec.exe -s -i 39 \computername notepad.exe
PsExec.exe -s -i 40 \computername notepad.exe
PsExec.exe -s -i 55 \computername notepad.exe
PsExec.exe -s -i 69 \computername notepad.exe
PsExec.exe -s -i 70 \computername notepad.exe

如果您想自动完成此过程,您可以:

  1. 使用powershell解析qwinsta输出(请参阅示例here
  2. 提取连接ID
  3. 自动生成并执行PsExec命令