在 Powershell 中运行远程 GUI 应用程序 [英] Running remote GUI app in Powershell

查看:85
本文介绍了在 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 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆