6

我有一个应用程序可以在任意 Windows 应用程序上进行一些自动化操作。我一直在用记事本测试它。

在这个自动化过程中,我必须从代​​码中调用事件。我目前支持两种类型的事件,因为它们似乎是最常见的,InvokePatternExpandCollapsePattern

我使用可以远程桌面进入的计算机进行测试。但这很奇怪。当我通过远程桌面连接到计算机时,应用程序运行良好。当我与计算机断开连接时,我的代码停止为 ExpandCollapsePattern 工作(InvokePattern 工作正常)。我得到一个 InvalidOperationException。

文档说只有当节点被标记为 LeafNode 时才应该抛出这个。我收到 InvalidOperationException 的远程桌面有何不同?

这是我目前必须执行该事件的代码。

ExpandCollapseState state =
    patternMenu.Current.ExpandCollapseState;
if (state == ExpandCollapseState.Expanded)
    patternMenu.Collapse();
else if (state == ExpandCollapseState.PartiallyExpanded ||
         state == ExpandCollapseState.Collapsed)
    patternMenu.Expand();

patternMenu 是使用 GetCurrentPattern 从 AutomationElement 获取的 ExpandCollapsePattern。

当我打印出该值时,ExpandCollapseState 的当前值是“Collapsed”。

编辑:我有没有机会知道为什么我被否决了,这是一个坏问题?我真的对正在发生的事情感到困惑,因为它似乎只在远程桌面关闭时才会失败。如果这是一个我应该知道答案的非常愚蠢的问题,我希望得到一个解释,然后投反对票。

与桌面交互的进程不是 Windows 服务。这是我在远程桌面进入计算机后启动的应用程序。是因为我锁定了桌面吗?

我在 Ubuntu 上使用“终端服务器客户端”登录 Windows 机器。按此应用程序上的关闭按钮是否会导致桌面锁定?

4

1 回答 1

2

一般来说,您通常不能在非交互式桌面上运行 UI 自动化或类似的东西。非交互式桌面在输入方面有各种限制:没有焦点元素,无法发送输入,因此任何依赖于这些的操作都会失败。

某些功能(例如发送 Windows 消息)可以正常工作。这里可能发生的是 InvokePattern 功能作为消息在幕后实现,因此仍然有效;但是展开/折叠可能会根据输入来实现,这会失败。

不清楚为什么在您的情况下,当您关闭客户端时它会失败(该部分是预期的),但在远程桌面锁定自身时似乎工作 - 它是否期望在两种情况下表现相同。

(Note that if the local Ubuntu desktop locks, all should be fine and still work, so long as the client still running. The remote client is still 'interactive' in that case, since it's got a live client attached to it, regardless of whether the client itself is running on an interactive or non-interactive desktop - the concepts may not even apply to a client running on another OS!)

于 2011-03-29T01:58:53.233 回答