private static bool DoAccTest(RunningWindowTableItemCollection list, IntPtr mainHandle, IntPtr childHandle, int maximumResultCount) { object accObject = Tools.WndUtils.Win32.AccessibleObjectFromWindow(childHandle); if (null != accObject) { string name = TypeDescriptor.GetClassName(accObject); string component = TypeDescriptor.GetComponentName(accObject); string className = Tools.WndUtils.Win32.GetClassName(childHandle); IntPtr processID = Tools.WndUtils.Win32.GetWindowThreadProcessId(childHandle); ProxyInformation.ProcessElevation elevation = Tools.WndUtils.ProcessElevation.ConvertToProcessElevation(Tools.WndUtils.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); } }
public Entry(object underlying, string id, string caption, string name, string component, string libraryID, string proceesID, ProxyInformation.ProcessElevation elevated) { Underlying = underlying; ID = id == Guid.Empty.ToString() ? "<Unknown>" : id; Caption = String.IsNullOrWhiteSpace(caption) ? "<Unknown>" : caption; Name = String.IsNullOrWhiteSpace(name) ? "<Unknown>" : name; Component = String.IsNullOrWhiteSpace(component) ? "<Unknown>" : component; Library = libraryID == String.Empty ? "<Unknown>" : libraryID; ProcessID = proceesID; Elevated = elevated; }
private static IDisposableEnumeration <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) { Tools.WndUtils.WindowEnumerator enumerator = new Tools.WndUtils.WindowEnumerator( target.MainClassName, target.MainClassNameEnd, (Tools.WndUtils.WindowEnumerator.FilterMode)Convert.ToInt32(target.NameCompare)); IntPtr[] mainHandles = enumerator.EnumerateWindows(_mainWindowTimeoutMilliseconds); if (null == mainHandles) { continue; } foreach (IntPtr item in mainHandles) { Tools.WndUtils.ChildWindowBatchEnumerator childEnumerator = new Tools.WndUtils.ChildWindowBatchEnumerator(item); foreach (string subItem in target.ChildPath) { childEnumerator.SearchOrder.Add( new Tools.WndUtils.ChildWindowBatchEnumerator.SearchCriteria(subItem)); } IntPtr[] childHandles = childEnumerator.EnumerateWindows(_childWindowTimeoutMilliseconds); if (null == childHandles) { continue; } foreach (IntPtr childHandle in childHandles) { object accObject = Tools.WndUtils.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 = Tools.WndUtils.Win32.GetWindowThreadProcessId(childHandle); ProxyInformation.ProcessElevation procElevation = Tools.WndUtils.ProcessElevation.ConvertToProcessElevation(Tools.WndUtils.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); }
private static IDisposableEnumeration<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) { Tools.WndUtils.WindowEnumerator enumerator = new Tools.WndUtils.WindowEnumerator( target.MainClassName, target.MainClassNameEnd, (Tools.WndUtils.WindowEnumerator.FilterMode)Convert.ToInt32(target.NameCompare)); IntPtr[] mainHandles = enumerator.EnumerateWindows(_mainWindowTimeoutMilliseconds); if (null == mainHandles) continue; foreach (IntPtr item in mainHandles) { Tools.WndUtils.ChildWindowBatchEnumerator childEnumerator = new Tools.WndUtils.ChildWindowBatchEnumerator(item); foreach (string subItem in target.ChildPath) { childEnumerator.SearchOrder.Add( new Tools.WndUtils.ChildWindowBatchEnumerator.SearchCriteria(subItem)); } IntPtr[] childHandles = childEnumerator.EnumerateWindows(_childWindowTimeoutMilliseconds); if (null == childHandles) continue; foreach (IntPtr childHandle in childHandles) { object accObject = Tools.WndUtils.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 = Tools.WndUtils.Win32.GetWindowThreadProcessId(childHandle); ProxyInformation.ProcessElevation procElevation = Tools.WndUtils.ProcessElevation.ConvertToProcessElevation(Tools.WndUtils.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; }
private static bool DoAccTest(RunningWindowTableItemCollection list, IntPtr mainHandle, IntPtr childHandle, int maximumResultCount) { object accObject = Tools.WndUtils.Win32.AccessibleObjectFromWindow(childHandle); if (null != accObject) { string name = TypeDescriptor.GetClassName(accObject); string component = TypeDescriptor.GetComponentName(accObject); string className = Tools.WndUtils.Win32.GetClassName(childHandle); IntPtr processID = Tools.WndUtils.Win32.GetWindowThreadProcessId(childHandle); ProxyInformation.ProcessElevation elevation = Tools.WndUtils.ProcessElevation.ConvertToProcessElevation(Tools.WndUtils.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; }
/// <summary> /// Returns all running com proxies + add. informations from the running object table there matched with the input parameters /// WARNING: the method returns always the first com proxy from the running object table if multiple (match) proxies exists. /// </summary> /// <returns>IDisposableEnumeration with proxy informations</returns> public static IDisposableEnumeration <ProxyInformation> GetActiveProxyInformations() { IEnumMoniker monikerList = null; IRunningObjectTable runningObjectTable = null; RunningObjectTableItemCollection resultList = new RunningObjectTableItemCollection(); try { // query table and returns null if no objects running if (GetRunningObjectTable(0, out runningObjectTable) != 0 || runningObjectTable == null) { return(null); } // query moniker & reset runningObjectTable.EnumRunning(out monikerList); monikerList.Reset(); IMoniker[] monikerContainer = new IMoniker[1]; IntPtr pointerFetchedMonikers = IntPtr.Zero; // fetch all moniker while (monikerList.Next(1, monikerContainer, pointerFetchedMonikers) == 0) { // query com proxy info object comInstance = null; runningObjectTable.GetObject(monikerContainer[0], out comInstance); if (null == comInstance) { continue; } string name = TypeDescriptor.GetClassName(comInstance); string component = TypeDescriptor.GetComponentName(comInstance, false); IBindCtx bindInfo = null; string displayName = String.Empty; Guid classID = Guid.Empty; if (CreateBindCtx(0, out bindInfo) == 0) { monikerContainer[0].GetDisplayName(bindInfo, null, out displayName); monikerContainer[0].GetClassID(out classID); Marshal.ReleaseComObject(bindInfo); } string itemClassName = TypeDescriptor.GetClassName(comInstance); string itemComponentName = TypeDescriptor.GetComponentName(comInstance); COMTypes.ITypeInfo typeInfo = null; string itemLibrary = String.Empty; if (classID != Guid.Empty) { typeInfo = TryCreateTypeInfo(comInstance); itemLibrary = null != typeInfo?GetParentLibraryGuid(typeInfo).ToString() : String.Empty; } string itemID = classID != Guid.Empty ? classID.ToString() : String.Empty; ProxyInformation entry = new ProxyInformation(comInstance, displayName, itemID, itemClassName, itemComponentName, itemLibrary, IntPtr.Zero, ProxyInformation.ProcessElevation.Unknown); resultList.Add(entry); if (classID != Guid.Empty && typeInfo != null) { ReleaseTypeInfo(typeInfo); } } return(resultList); } catch (Exception exception) { DebugConsole.Default.WriteException(exception); throw; } finally { // release proxies if (runningObjectTable != null) { Marshal.ReleaseComObject(runningObjectTable); } if (monikerList != null) { Marshal.ReleaseComObject(monikerList); } } }