Пример #1
0
        private static bool DoAccTest(RunningWindowTableItemCollection list, IntPtr mainHandle, IntPtr childHandle, int maximumResultCount)
        {
            object accObject = Win32.AccessibleObjectFromWindow(childHandle);

            if (null != accObject)
            {
                string name      = TypeDescriptor.GetClassName(accObject);
                string component = TypeDescriptor.GetComponentName(accObject);
                string className = Win32.GetClassName(childHandle);
                IntPtr processID = Win32.GetWindowThreadProcessId(childHandle);
                ProxyInformation.ProcessElevation elevation = ProcessElevation.ConvertToProcessElevation(ProcessElevation.IsProcessElevated(processID));
                COMTypes.ITypeInfo typeInfo  = RunningObjectTable.TryCreateTypeInfo(accObject);
                string             id        = GetTypeGuid(typeInfo).ToString();
                string             libraryID = RunningObjectTable.GetParentLibraryGuid(typeInfo).ToString();
                if (null != typeInfo)
                {
                    RunningObjectTable.ReleaseTypeInfo(typeInfo);
                }
                ProxyInformation item =
                    new ProxyInformation(accObject, String.Format("{0}-{1}", childHandle, className), id, name, component, libraryID, processID, elevation);
                if (list.Count <= maximumResultCount)
                {
                    list.Add(item);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Creates an instance of the class
 /// </summary>
 /// <param name="proxy">proxy from ROT</param>
 /// <param name="displayName">display name in running object table</param>
 /// <param name="id">interface id</param>
 /// <param name="name">name of the managed proxy class if exists</param>
 /// <param name="component">name of the component where the proxy comes from</param>
 /// <param name="libraryID">id of the component where the proxy comes from</param>
 /// <param name="processID">pid</param>
 /// <param name="elevation">process elevation</param>
 public ProxyInformation(object proxy, string displayName, string id, string name,
                         string component, string libraryID, IntPtr processID, ProcessElevation elevation)
 {
     if (null == proxy)
     {
         throw new ArgumentNullException("proxy");
     }
     Proxy       = proxy;
     DisplayName = displayName;
     ID          = id == Guid.Empty.ToString() ? "<Unknown>" : id;
     Name        = String.IsNullOrWhiteSpace(name) ? "<Unknown>" : name;
     Component   = String.IsNullOrWhiteSpace(component) ? "<Unknown>" : component;
     Library     = libraryID == Guid.Empty.ToString() ? "<Unknown>" : libraryID;
     ProcessID   = processID;
     Elevation   = elevation;
 }
Пример #3
0
        private static IDisposableSequence <ProxyInformation> GetKnownAccessibleProxiesFromPath(IEnumerable <AccessibleWindowTarget> targets, int maximumResultCount)
        {
            if (null == targets)
            {
                throw new ArgumentNullException("targets");
            }

            RunningWindowTableItemCollection result = new RunningWindowTableItemCollection();

            if (maximumResultCount <= 0)
            {
                return(result);
            }

            foreach (AccessibleWindowTarget target in targets)
            {
                WindowEnumerator enumerator =
                    new WindowEnumerator(
                        target.MainClassName, target.MainClassNameEnd, (WindowEnumerator.FilterMode)Convert.ToInt32(target.NameCompare));
                IntPtr[] mainHandles = enumerator.EnumerateWindows(_mainWindowTimeoutMilliseconds);
                if (null == mainHandles)
                {
                    continue;
                }
                foreach (IntPtr item in mainHandles)
                {
                    ChildWindowBatchEnumerator childEnumerator =
                        new ChildWindowBatchEnumerator(item);

                    foreach (string subItem in target.ChildPath)
                    {
                        childEnumerator.SearchOrder.Add(
                            new ChildWindowBatchEnumerator.SearchCriteria(subItem));
                    }
                    IntPtr[] childHandles = childEnumerator.EnumerateWindows(_childWindowTimeoutMilliseconds);
                    if (null == childHandles)
                    {
                        continue;
                    }

                    foreach (IntPtr childHandle in childHandles)
                    {
                        object accObject = Win32.AccessibleObjectFromWindow(childHandle);
                        if (null != accObject && accObject is MarshalByRefObject)
                        {
                            object targetProxy = null;
                            if (!String.IsNullOrEmpty(target.AccPropertyName))
                            {
                                targetProxy = TryInvokeProperty(accObject, target.AccPropertyName);
                                Marshal.ReleaseComObject(accObject);
                            }
                            else
                            {
                                targetProxy = accObject;
                            }

                            if (null != targetProxy)
                            {
                                string             itemComponentName = TypeDescriptor.GetComponentName(targetProxy);
                                COMTypes.ITypeInfo typeInfo          = RunningObjectTable.TryCreateTypeInfo(targetProxy);
                                string             library           = RunningObjectTable.GetParentLibraryGuid(typeInfo).ToString();
                                string             id            = GetTypeGuid(typeInfo).ToString();
                                string             itemClassName = TypeDescriptor.GetClassName(targetProxy);
                                string             itemCaption   = itemClassName;
                                if (!String.IsNullOrWhiteSpace(itemClassName) && !String.IsNullOrWhiteSpace(itemComponentName))
                                {
                                    itemCaption = String.Format("{0} {1}", itemComponentName, itemClassName);
                                }

                                IntPtr procID = Win32.GetWindowThreadProcessId(childHandle);
                                ProxyInformation.ProcessElevation procElevation =
                                    ProcessElevation.ConvertToProcessElevation(ProcessElevation.IsProcessElevated(procID));

                                ProxyInformation info = new ProxyInformation(targetProxy,
                                                                             itemCaption, id, itemClassName, itemComponentName, library, procID, procElevation);

                                result.Add(info);
                                if (null != typeInfo)
                                {
                                    RunningObjectTable.ReleaseTypeInfo(typeInfo);
                                }

                                if (result.Count >= maximumResultCount)
                                {
                                    return(result);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }