/// <summary> /// Get a list of accessible desktop objects. /// </summary> /// <param name="desired_access">The desired access for the desktops.</param> /// <returns>The list of desktops.</returns> public IEnumerable <NtDesktop> GetAccessibleDesktops(DesktopAccessRights desired_access) { foreach (string desktop in Desktops) { using (ObjectAttributes obj_attr = new ObjectAttributes(desktop, AttributeFlags.CaseInsensitive, this)) { var result = NtDesktop.Open(obj_attr, 0, desired_access, false); if (result.IsSuccess) { yield return(result.Result); } } } }
/// <summary> /// Get a list of accessible desktop objects. /// </summary> /// <param name="desired_access">The desired access for the desktops.</param> /// <returns>The list of desktops.</returns> public IEnumerable <NtDesktop> GetAccessibleDesktops(DesktopAccessRights desired_access) { using (var list = new DisposableList <NtDesktop>()) { foreach (string desktop in Desktops) { using (ObjectAttributes obj_attr = new ObjectAttributes(desktop, AttributeFlags.CaseInsensitive, this)) { var result = NtDesktop.Open(obj_attr, 0, desired_access, false); if (result.IsSuccess) { list.Add(result.Result); } } } return(list.ToArrayAndClear()); } }
/// <summary> /// Enumerate window handles. /// </summary> /// <param name="desktop">Desktop containing the Windows. Optional.</param> /// <param name="parent">The parent Window. Optional.</param> /// <param name="enum_children">True to enumerate child Windows.</param> /// <param name="hide_immersive">Hide immersive Windows.</param> /// <param name="thread_id">The thread ID that owns the Window.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The enumerated Window Handles.</returns> public static NtResult <IEnumerable <NtWindow> > GetWindows(NtDesktop desktop, NtWindow parent, bool enum_children, bool hide_immersive, int thread_id, bool throw_on_error) { int count = 64; while (true) { IntPtr[] handles = new IntPtr[count]; NtStatus status = NtSystemCalls.NtUserBuildHwndList(desktop.GetHandle(), parent.Handle, enum_children, hide_immersive, thread_id, handles.Length, handles, out int required_count); if (status.IsSuccess()) { return(handles.Take(required_count).Select(i => new NtWindow(i)).CreateResult()); } if (status != NtStatus.STATUS_BUFFER_TOO_SMALL || count > required_count) { return(status.CreateResultFromError <IEnumerable <NtWindow> >(throw_on_error)); } count = required_count; } }
protected override sealed NtResult <NtDesktop> OpenInternal(ObjectAttributes obj_attributes, DesktopAccessRights desired_access, bool throw_on_error) { return(NtDesktop.Open(obj_attributes, CreateDesktopFlags.None, desired_access, throw_on_error)); }
/// <summary> /// Enumerate window handles. /// </summary> /// <param name="desktop">Desktop containing the Windows. Optional.</param> /// <param name="parent">The parent Window. Optional.</param> /// <param name="enum_children">True to enumerate child Windows.</param> /// <param name="hide_immersive">Hide immersive Windows.</param> /// <param name="thread_id">The thread ID that owns the Window.</param> /// <returns>The enumerated Window Handles.</returns> public static IEnumerable <NtWindow> GetWindows(NtDesktop desktop, NtWindow parent, bool enum_children, bool hide_immersive, int thread_id) { return(GetWindows(desktop, parent, enum_children, hide_immersive, thread_id, true).Result); }