我正在尝试构建一个简单的环境来自动截图。我有多个 Hyper-V 虚拟机,我需要使用 PowerShell Direct 以特殊顺序在它们上运行命令。当我运行 psexec
通过 PowerShell Direct 打开 notepad.exe
时,记事本的窗口打开,但它是空白的。我可以盲目地单击窗口上的控件(例如工具栏上的控件),看起来它们可以工作,但除了空白窗口之外实际上什么也没有显示。
我现在看到的在现有 session 中打开 Windows 的唯一简单选项是运行 psexec
(任何其他建议将不胜感激,因为我尝试坚持仅使用 PowerShell 的方法遇到了障碍,请参阅Starting a GUI application on a guest VM with PowerShell Direct)。
我在其中一台虚拟机上运行 psexec
,以在 session 2 中启动 notepad.exe
。此 PowerShell 代码段在主机虚拟机上运行,它通过 PowerShell 与 guest 虚拟机联系直接。
Invoke-Command -VMName 'client1.example.com' -Credential $credential -ScriptBlock {
C:\bin\psexec.exe \\client1.example.com -i 2 "notepad.exe"
}
notepad.exe
启动,但窗口为空白。这是 psexec
中的错误吗?
请看截图:
当我直接在 guest 虚拟机中运行 psexec
时,不会出现此问题。
C:\bin\psexec.exe \\client1.example.com -i 2 "notepad.exe"
最佳答案
通过添加-s
选项解决。我不明白为什么会出现这个问题,也不明白“在系统帐户中”运行它有何帮助。
-s Run the remote process in the System account.
顺便说一句,当我启动 explorer.exe
时,问题不会发生。
关于windows - 使用 PowerShell Direct 时,通过 psexec 打开的窗口为空白,但当 psexec 本地启动时,窗口正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62478070/