Beispiel #1
0
 /// <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());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Get a list of accessible Window Station objects.
        /// </summary>
        /// <param name="desired_access">The desired access for the Window Stations.</param>
        /// <returns>The list of desktops.</returns>
        public static IEnumerable <NtWindowStation> GetAccessibleWindowStations(WindowStationAccessRights desired_access)
        {
            using (var list = new DisposableList <NtWindowStation>()) {
                string base_path = GetWindowStationBase();

                foreach (string name in WindowStations)
                {
                    string full_path = $@"{base_path}\{name}";
                    using (ObjectAttributes obj_attr = new ObjectAttributes(full_path, AttributeFlags.CaseInsensitive)) {
                        var result = Open(obj_attr, desired_access, false);
                        if (result.IsSuccess)
                        {
                            list.Add(result.Result);
                        }
                    }
                }
                return(list.ToArrayAndClear());
            }
        }
Beispiel #3
0
 /// <summary>
 /// Gets all accessible threads on the system.
 /// </summary>
 /// <param name="desired_access">The desired access for each thread.</param>
 /// <param name="from_system_info">Get the thread list from system information.</param>
 /// <returns>The list of accessible threads.</returns>
 public static IEnumerable <NtThread> GetThreads(ThreadAccessRights desired_access, bool from_system_info)
 {
     if (from_system_info)
     {
         return(NtSystemInfo.GetProcessInformation().SelectMany(p => p.Threads)
                .Select(t => Open(t, desired_access, false)).SelectValidResults());
     }
     else
     {
         using (var threads = new DisposableList <NtThread>())
         {
             using (var procs = NtProcess.GetProcesses(ProcessAccessRights.QueryInformation).ToDisposableList())
             {
                 foreach (var proc in procs)
                 {
                     threads.AddRange(proc.GetThreads(desired_access));
                 }
             }
             return(threads.ToArrayAndClear());
         }
     }
 }