protected AutomationElement getWindowElement(IntPtr hWndMain) { AutomationElement retVal = null; try { retVal = AutomationElement.FromHandle(hWndMain); } catch { retVal = null; } return retVal; }