在 Powershell 中运行远程 GUI 应用程序
我们有一个自定义组件,它封装了 powershell 的一些功能,因此可以在 BizTalk 2006 中使用。对于大多数操作(检查文件路径、复制或移动文件),这都可以正常工作。然而,我们需要远程启动 GUI 应用程序来进行一些处理。组件本身处理与远程盒子的连接,我们所要做的就是设置一些参数,然后告诉它执行命令
Start-Process -FilePath "path to exe" -ArgumentList "arguments for exe" -WorkingDirectory "workingdir for exe"
问题是这样的:如果我们从盒子本身的 powershell 命令行运行它,那么效果很好。然而,当我们远程启动它时(从 BizTalk、从测试工具,甚至使用远程 Powershell 命令行并通过 Start-PSSession 连接),该应用程序将短暂运行然后退出,而不实际执行任何操作。我怀疑,因为有问题的 exe 需要加载 GUI 才能运行该进程,所以正是这个导致了问题。我已经尝试了我能想到的一切,包括 -NoNewWindow 和 -WindowStyle 但无济于事。任何帮助使这项工作正常进行将不胜感激。
注意:我们无权访问我们尝试运行的应用程序的源代码,因为它是较旧的 win32 应用程序,并且没有提供该应用程序的批处理或命令行版本。
We have a custom comonent that wraps some of the functionality of powershell so it can be used frim BizTalk 2006. For most operations (checking a file path, copy or move a file) this works fine. However we have the need to fire up a GUI app remotely to do some processing. The component itself handles the connection to the remote box, all we have to do is set some parameters and then tell it to execute a command
Start-Process -FilePath "path to exe" -ArgumentList "arguments for exe" -WorkingDirectory "workingdir for exe"
The issue is this: If we run this from a powershell command line on the box itself, this works fine. However when we fire it up remotely (from BizTalk, from a test harness, even using a remote Powershell command line and connection via Start-PSSession), this app will run briefly then exit without actually doing anything. My suspicion is that because the exe in question requires a GUI to load to run the process, that it is this that is causing an issue. I've tried everything I can think of, including -NoNewWindow and -WindowStyle but to no avail. Any help getting this working would be very much appreciated.
Note: We do not have access to the source for the application we are trying to run as it is an older win32 application, and no batch or command line version of this application has been supplied.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用标准 PowerShell 方法(WinRM、WMI),您无法使用 GUI 启动应用程序。我知道的唯一解决方案是使用 SysInternals 的 PsExec (或类似的工具)。它可以启动向用户呈现 GUI 的应用程序。您的命令行将如下所示:
-accepteula
— 静默接受 EULA。-i
— 允许 GUI。其他解决方案更加hacky,包括将任务远程添加到调度程序。
Using standard PowerShell methods (WinRM, WMI) you can't launch applications with GUI. The only solution I know about is to use PsExec from SysInternals (or similar tools). It can launch applications which present GUI to the user. Your command line will look like this:
-accepteula
— silently accept EULA.-i
— allow GUI.Other solutions are more hacky, including remote adding of tasks to the scheduler.
由于我最近遇到了这个问题,这是我使用 Discord 添加远程任务的建议的解决方案。与必须设置单独的工具相比,我更喜欢“黑客”。
Since I came across this recently, here is my solution using Discord's suggestion of adding a remote task. I preferred the "hack" over having to setup a separate tool.