UI Automation没有看到隐藏的窗口? [英] UI Automation doesn't see hidden windows?

查看:148
本文介绍了UI Automation没有看到隐藏的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有已签名的Winforms应用程序,其清单带有level ="requireAdministrator" uiAccess ="false".
我想使用隐藏窗口启动另一个应用程序,并使用UI Automation API对其进行处理.

I have winforms application that is signed and has manifest with level="requireAdministrator" uiAccess="false".
I want to start another application with hidden window and to work with it using UI Automation API.

        Process procinst = new Process();
        procinst.StartInfo = new ProcessStartInfo()
        {
            WindowStyle = ProcessWindowStyle.Hidden,
            UseShellExecute = true,
            ErrorDialog = true,
            Verb = "runas",
            FileName = appfilepath
        };           
        procinst.Start();

带有隐藏窗口的新进程可以在Spy ++中看到,但不能在UISpy中看到,我也无法使用FindFirst方法找到它:

The new process with hidden window can be seen in Spy++ but not in UISpy and I cannot also find it using FindFirst method:

mainwnd = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "apptitle"));

当最小化ProcessWindowStyle时,一切都很好,而当其被隐藏时,一切都会停止.
是UI预期的行为吗?UI Automation无法访问隐藏的窗口?有什么办法可以破解吗?

When ProcessWindowStyle is Minimized everything goes fine, when it is Hidden - everything stops.
Is it expected UI Automation behavior? UI Automation cannot access hidden windows? Is there any way to hack it?

推荐答案

这很可悲,但这是事实:

That's sad but that's true:

UIA中确实没有隐形"或背景"元素之类的东西 –元素消​​失后,它将不再位于UIA树中.对于辅助技术来说这是一件好事(不需要修剪树),但是对于UI自动化框架可能会很麻烦.从历史上看,我们倾向于缓存UI元素,因此我们可以更快地重新获得它们.必要时,可以将ShowWindow和accSelect与SELFLAG_TAKEFOCUS混合使用.这不再起作用.例如,如果工具窗口位于选项卡中而不位于前台;我们缓存的元素将因为无效而无效,如果需要,我们需要a)将其放到前台,b)重新从头开始查找该元素.

There is not really such a thing as an "invisible" or "background" elements in UIA – when an element is gone, it will no longer be in the UIA tree. This is a good thing for assistive technologies (less pruning of the tree required), but can be troublesome for UI Automation frameworks. Historically we would tend to cache UI elements so we could get back to them again faster. When needed, one could call a mix of ShowWindow and accSelect with SELFLAG_TAKEFOCUS. This no longer works. If, say, a tool window is tabbed and not in the foreground; our cached element for it will because invalid, and if it’s requested we need to a) bring it into the foreground and b) find the element from scratch again.

查看全文

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