我有一些用于从 Chrome 中提取 url 的 C# 代码。它通常适用于 Win7/Win 8.1,但在某些具有相同配置的计算机上则不起作用。而且,这些配置之间可能没有区别。为什么会这样?
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.
...
}