本文介绍了Microsoft UIAutomation始终不能在某些计算机上运行. C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些C#代码,用于从Chrome提取网址.它通常可以在Win7/Win 8.1上运行,但是在某些具有相同配置的计算机上却无法正常工作.而且,这些配置之间可能没有区别.为什么会发生?

I have some C# code for extracting url from Chrome.It usually works on Win7/Win 8.1, but on some computers with the same configuration it doesn't work. And, probably, there is no difference between these configurations.Why does it happen?

Process[] procsChrome = Process.GetProcessesByName("chrome");
foreach(Process chrome in procsChrome)
{
   if(chrome.MainWindowHandle == IntPtr.Zero)
   {
    continue;
   }
   AutomationElement mainWindow = AutomationElement.FromHandle(chrome.MainWindowHandle);
   elmUrlBar = mainWindow.FindFirst(TreeScope.Descendants,  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));

  //elmUrlBar on some computers inited, on some NULL. But versions of Chrome are identical.
...
}

推荐答案

(1)您是否已验证在应用程序失败的情况下在Chrome中启用了辅助功能?必须从Chrome的命令行中启用它,或者为各个选项卡将其打开.

(1) Have you verified that Accessibility was turned on in Chrome in those situations where your application failed? It either must be enabled from the Chrome's command line or turned on for individual tabs.

(2)您可能已经违反了用户界面特权隔离(UIPI).如果您正在运行管理员登录名,这不是问题,但是使用标准登录名,绕过UIPI的要求是:

(2) You may have run afoul of User Interface Privilege Isolation (UIPI). It's not a problem if you're running an Admin login, but with a Standard login the requirements to bypass UIPI are:

  1. 在应用程序的清单中有uiAccess = True.
  2. 通过有效的代码签名机构对应用程序进行签名. (不过,您可以使用自签名的可执行文件进行测试-我们已经成功完成了该任务.)
  3. 将可执行文件安装到System32目录(对于安装在64位Windows上的32位应用程序,则为SysWOW64).

这篇关于Microsoft UIAutomation始终不能在某些计算机上运行. C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:37