在 Powershell 中运行远程 GUI 应用程序

编程入门 行业动态 更新时间:2024-10-11 17:22:06
本文介绍了在 Powershell 中运行远程 GUI 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个自定义组件,它封装了 powershell 的一些功能,因此可以在 BizTalk 2006 中使用它.对于大多数操作(检查文件路径、复制或移动文件),这可以正常工作.然而,我们需要远程启动一个 GUI 应用程序来进行一些处理.组件本身处理与远程框的连接,我们所要做的就是设置一些参数,然后告诉它执行命令

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"

问题是这样的:如果我们从盒子本身的 powershell 命令行运行它,这工作正常.然而,当我们远程启动它时(从 BizTalk,从测试工具,甚至使用远程 Powershell 命令行和通过 Start-PSSession 连接),这个应用程序将短暂运行然后退出,实际上不做任何事情.我的怀疑是,因为有问题的 exe 需要加载 GUI 才能运行该进程,这就是导致问题的原因.我已经尝试了所有我能想到的方法,包括 -NoNewWindow 和 -WindowStyle 但无济于事.非常感谢您帮助完成这项工作.

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.

注意:我们无法访问我们尝试运行的应用程序的源代码,因为它是一个较旧的 win32 应用程序,并且未提供此应用程序的批处理或命令行版本.

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.

推荐答案

使用标准 PowerShell 方法(WinRM、WMI),您无法使用 GUI 启动应用程序.我所知道的唯一解决方案是使用 来自 SysInternals 的 PsExec(或类似的工具).它可以启动向用户呈现 GUI 的应用程序.您的命令行将如下所示:

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:

& ".\psexec" -accepteula -i "\\computername" -u "domain\username" -p "password" "command line"

  • -accepteula — 默默接受 EULA.
  • -i — 允许 GUI.
    • -accepteula — silently accept EULA.
    • -i — allow GUI.
    • 其他解决方案更加笨拙,包括将任务远程添加到调度程序.

      Other solutions are more hacky, including remote adding of tasks to the scheduler.

更多推荐

在 Powershell 中运行远程 GUI 应用程序

本文发布于:2023-11-25 05:57:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Powershell   GUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!